简体   繁体   中英

PHP Crypt encrypt/decrypt not returning the same hash tag

Sign up form - Password is 123456:

$pwd = $_POST['pwd'];
$salt = '$2a$10$R.Baj0mvj5doNvtvzDjwP5$';
$password = crypt("$pwd", $salt);

Hash in the database:

$2a$10$R.Baj0mvj5doNvtvzDjwPuN/W8Z3n6RVGyM0pM

Hash comparison when user is login in - Password again, 123456:

$salt = '$2a$10$R.Baj0mvj5doNvtvzDjwP5$';
$crypt_pass=crypt($password,$salt);

The $crypt_pass = $2a$10$R.Baj0mvj5doNvtvzDjwPuN/W8Z3n6RVGyM0pMQB89k2m9nYRIN6O The password hash in the database is: $2a$10$R.Baj0mvj5doNvtvzDjwPuN/W8Z3n6RVGyM0pM

Why aren't they matching when I'm hashing them with the same salt?

You're using Blowfish as your hash type. That will always return different values for the same string and salt. If you want your hashes to match use SHA 512.

$salt = '$6$rounds=5000$usesomesillystringforsalt$';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM