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