note 10386 added to crypt

From: Date: Sun, 31 Dec 2000 02:17:43 +0000
Subject: note 10386 added to crypt
Groups: php.notes 
Request: Send a blank email to php-notes+get-9286@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; }; http://www.php.net/manual/function.crypt.php

« previous php.notes (#9286) next »