0

I'm using a Debian 7.0 with PHP 5.3.3-7+squeeze14 with Suhosin-Patch (cli).

I need to build an htpasswd files from a form (data stored with MySQL).

I tried that but didn't work:

$hash = crypt($_POST['password'], base64_encode($_POST['password'])); //didn't work

$hash = crypt($_POST['password']); //didn't work

$hash = crypt($_POST['password'], substr($_POST['password'])); //didn't work



$cset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./"; 
$salt = ""; 
for ($i=0; $i<CRYPT_SALT_LENGTH; $i++) ``
    $salt .= substr($cset, rand() & 63, 1); 
$hash = crypt($_POST['password'], $salt); // didn't work

Someone can explain me how i can get the same result as htpasswd using PHP ? It's depend on my debian ? My /usr/bin/htpasswd script ?

Thanks !

Hihui
  • 1
  • 2
  • What do you mean by *didn't work*? Is it because generated values are different? `htpasswd` use a random salt, thus generated values will always be different. – Guillaume Poussel Oct 16 '13 at 12:24
  • Hi, I mean i can't access folder with the apache's authentification (htaccess). I know all values will be different. But i can't perform a correct login :(* – Hihui Oct 16 '13 at 12:25
  • Thanks a lot ! It's seem to be correct ! So, a simple salt like 'aa' do the stuff .. – Hihui Oct 16 '13 at 12:38
  • I removed my comment instead of editing it to fix a typo... Answer your own question and mark it as solved when you're done ;) – Guillaume Poussel Oct 16 '13 at 12:39
  • I can't answer now ... Need to wait 7h :(. So i post here : Guillaume Poussel give me the solution: I need to use a simple salt like 'aa'. So my code: $hash = crypt($_POST['password'], 'aa'); And now, i can login correctly ! – Hihui Oct 16 '13 at 12:50

0 Answers0