note 10386 deleted from function.crypt by jimw
| From: | jimw@php.net | Date: | Sun, 16 Dec 2001 20:24:51 +0000 |
| Subject: | note 10386 deleted from function.crypt by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-22937@lists.php.net to get a copy of this message | ||
There's an easy way to verify that a plain text password entered by a user matches the stored
encrypted password.
Use the encrypted password as the salt for the crypt function. I know it sounds a little wierd, but
that's how it's supposed to work.
See 'perldoc -f crypt' for more detailed info.
Here's an example:
A user sets up his or her account and chooses the password "bannana" . You encrypt the
password with crypt() and store it somewhere (database, file, wherever).
Later the user returns to the site and enters the password "bannana" in a form. You need
to compare the plain text password just entered with the stored encrypted password.
"$stored_password" is the encrypted, stored password.
"$password" is the plain text password you just got from the form.
## Check the passwords
$encrypted_password = crypt($password,$stored_password);
if ($encrypted_password = $stored_password) { $logged_in = 1; };