Question

Hi I am trying to set up a .htaccess and a .htpasswd file to see if a user can have access to a particular directory. When a new user registers, their passwords are encrypted with the PHP md5() function and then stored in the database with their other login info. I would like to add a few of their encrypted passwords into my .htpasswd file dynamically so that they can enter into a sub member section. I am having trouble because the .htpasswd file would work with passwords encrypted with the crypt() function but i am not sure how to get it to work with their md5 encrypted passwords.

Était-ce utile?

La solution

Documentation says:

htpasswd encrypts passwords using either a version of MD5 modified for Apache, or the system's crypt() routine. Files managed by htpasswd may contain both types of passwords; some user records may have MD5-encrypted passwords while others in the same file may have passwords encrypted with crypt().

I think you can explicitly specify apache to use md5s for password in htpasswd file using -m argument to htpasswd

If you don't want or can't use the htpasswd tool, you can create crypt() based passwords from PHP:

$clearTextPassword = 'some password';
$password = crypt($clearTextPassword, base64_encode($clearTextPassword));

Autres conseils

"I think you can explicitly specify apache to use md5s for password in htpasswd file using -m argument to htpasswd"

I just found out the exact opposite in Ubuntu 12.04 and newer, it defaults to md5 and you have to use the -d flag to get it to use Crypt. This might be the case elsewhere too, I can't seem to find a version number for htpasswd.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top