Hi Estella,
Your question intrigued me a little so I decided to look into it.
First when you encrypt the password you need to use Standard DES-based encryption with a two character salt.
PHP Code:
$salt = 'MR'; /* This ideally would be randomly generated */
$password = 'thePassword';
$hash = crypt($password, $salt);
echo $hash;
In the example above I set the salt to MR.
This produces the $hash = MRxMiKl2Nkovw
Now if you need to compare a password to the hashed version you need to use the same salt value (which is the first two characters of the hash result). This is what Apache does (I believe).
PHP Code:
$oldHash = 'MRxMiKl2Nkovw';
$salt = substr($oldHash, 0, 2); /* i.e. MR */
$password = 'thePassword';
$hash = crypt($password, $salt);
echo $hash;
This will produce the same hashed value (hence the password matches).
I'm still getting my head around this so I'm not sure if I've explained it clearly, but the code may help?
Regards,
Mark
Bookmarks