authentication - Why is php password_verify and password_hash using different encryption identifiers? -


after troubleshooting, have determined when hash password using php's password_hash function, encryption identifier $2y$. however, when use password_verify function compare stored hashed password user input password, password_verify not return true. if generate new password using $2a$ identifier on https://www.bcrypt-generator.com/ , replace stored hashed password it, returns true.

i'm hoping can explain why password_hash($password, password_default) using $2y$ , why password_verify() using $2a$. or else might doing wrong here matter. doing locally on wamp server running php version 7.0.10.

here example of code having trouble ($2y$ identifier not return true).

<?php // $hashnotworking came password_hash("testing", password_default)."\n"; $hashnotworking = '$2y$10$dnpos6f7vo4z2iryu./ecobd7bmkwlkk9yiyjb0hvni14b1dbfhbc';  if (password_verify('testing', $hashnotworking)) {  echo 'password valid!'; } else {  echo 'invalid password.'; } ?> 

here example of code working ($2a$ encryption not generated password_hash function).

<?php // $hashworking came https://www.bcrypt-generator.com/ $hashworking = '$2a$08$up75n/pdhuzo6qoom3dupug5u2fcsxw4f3muz8p3slo5ypz4flf9o';  if (password_verify('testing', $hashworking)) {  echo 'password valid!'; } else {  echo 'invalid password.'; } ?> 

thanks in advance help.

i suspect there might have been whitespace introduced in original hash and/or <br>, or may have been introduced user.

i have seen cases before.

if case, trim() it.

create new hash per mentioned in comments , work.

echo $var = password_hash("testing", password_default)."\n"; 

then paste in place of present hash is.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -