Password hashing issue in PHP - password_verify() always returns false
P粉481035232
P粉481035232 2023-07-30 14:51:07
0
1
365
<p>I have a problem with password hashing in PHP. I use the password_hash() function to hash the admin password when registering and store it in the database. However, when logging in, when I try to verify the password using password_verify(), it always returns false, even though I'm sure the password is correct. </p><p>Here is a summary of my code: </p><p><br /></p> <pre class="brush:php;toolbar:false;">$adminPassword = "test123"; $adminPasswordHash = password_hash($adminPassword, PASSWORD_BCRYPT); // ... Store $adminPasswordHash in the database ... // During login: $adminInputPassword = "test123"; $adminPasswordHashVERIFY = "$2y$10$o4qspRTirOSdyGtwHCxt6ee2i0BNChl3mEPazxVbmb534kw3ACHCm"; if (password_verify($adminInputPassword, $adminPasswordHashVERIFY)) { echo "Password is correct!"; } else { echo "Password is incorrect!"; }</pre> <p>I made sure $adminPassword and $adminInputPassword have the same value, but the validation always returns false. I also tried using the password_hash() function and passing PASSWORD_DEFAULT as parameter instead of PASSWORD_BCRYPT, but the result was the same. </p><p>Am I missing something during the hash generation or verification process? Any help or insight into this issue would be greatly appreciated. Thanks! </p><p><br /></p>
P粉481035232
P粉481035232

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!