<?PHP
//this example very simple, check the other one to see more
$password_raw = 'the password to hash';
require_once 'class_password.php';
$pwd = new Password();
//* gen new hash *
$password = $password_raw; //password provided by user
$hash = $pwd->hash($password); //hash the password
echo "The hash of the password is: <br />".$hash;
//$hash now contains the hashed pw, store this value in your db since we need it
//when the user wants to login again
//I will output the hash into a textbox for this example.
//this will validate the stored hash against the entered plain thext password
$db_hash = $hash; //retrieve previously generated hash. this should come from a database
$password = $password_raw; //password provided by user
$hash = $pwd->re_hash( $db_hash, $password ); //hash the entered password with the salt of db_hash
//
//if the entered pw is correct then $hash and the hash from your db must match exactly ===
if( $hash === $db_hash )
echo '<h1>Valid password</h1>';
else
echo '<h1>Invalid password</h1>';
?>
|