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
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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.