Jump to content

encrypting password for .htpasswd


carbomite

Recommended Posts

Hi,

 

I am trying to create .htaccess and .htpasswd files in PHP using fopen and fwrite.

But I don't think I'm encrypting the password correctly for the .htpasswd file.

When I enter the username and password on the protected page, I am asked to enter them again.

My error logs say "Password Mismatch".

 

I have tried encrypting with:

$encrypwd = crypt($pwd);

and

$encrypwd = md5($pwd);

 

my username, password and create .htpasswd code

$name = "6";
$pwd = "6";

$hpfile = $name."/private/.htpasswd";
$fh2 = fopen($hpfile, 'w') or die("can't open file");
$stringData = $name.":".$encrypwd;
fwrite($fh2, $stringData);
fclose($fh2);

 

When I create a .htpasswd manually (entering the username and using an online htpasswd generator for the encrypted password) I am successful.

 

I am using Xampp Lite, Windows 7, PHP Version 5.3.1

In case it matters

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/222441-encrypting-password-for-htpasswd/
Share on other sites

when using

$encrypwd = md5($pwd);

the .htpasswd file has "6:1679091c5a880faf6fb5e6087eb1b2dc"

 

when using

$encrypwd = crypt($pwd);

the .htpasswd file has "6:$1$5V0.oV5.$1nmiJJQI5hEcgpfBVwPqa0"

 

these give me the "Password Mismatch" error in the logs

 

but when using an online generator (http://www.htaccesstools.com/htpasswd-generator) I put "6:$apr1$Og2ky/..$0Vs5LvxD54.f3MBEufzNE0" in the .htpasswd file and it works as expected when I log in

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.