Here's what the on-line manual has to say about it :
$password = crypt('mypassword'); // let the salt be automatically generated
/ You should pass the entire results of crypt() as the salt for comparing a
password, to avoid problems when different hashing algorithms are used. (As
it says above, standard DES-based password hashing uses a 2-character salt,
but MD5-based hashing uses 12.) /
if (crypt($user_input, $password) == $password) {
echo "Password verified!";
}
I took the encrypted password that was returned. I then plugged it into the function call as shown and ran it again. But surprise. No match. Why? Because the function encrypted the password again! Stupid, I know.
Now since there is no "decrypt" function, how are you supposed to be able to bang the encrypted password against the user input and check for a match? One-way encryption functions ain't much use, if you ask me. It's sort of like "write-only" memory. :rolleyes:
The process should be more like :
- encrypt the user's password
- store it somewhere (DB table, whatever)
- take user input and retrieve password from table
- de-encrypt password and compare with user input for match