php - How can I compare a hashed password with user input? -
i trying match , verify password user has input via $_post , hashed password in database. problem when hash input password, bcrypt produces new hash each time meaning no 2 hashes same give me no match. how can possibly match bcrypt hashed passwords? thank help!
login:
$password = password_hash(htmlentities($_post['password']), password_bcrypt, array( 'cost'=>14)); $stmt = $mcon->prepare("select `password` members password=:password"); $stmt->bindparam(":password", $password); $stmt->execute(); //get_result $data_array = $stmt->fetch(pdo::fetch_assoc); //echo passwords echo 'password form: ' . $password . '<br />'; echo 'password db: ' . $data_array['password'] . '<br />'; //verify password if (password_verify($password , $data_array)) { echo 'success'; exit(); }else{ echo 'try again m9'; exit(); } //if $_post password , $hashedpassword match start session $stmt->close(); $mcon->close();
another error in code: funtcion password_verify
needs hash-string second parameter. not confuse php-hash-datastructure. need call this:
$password_input = $_post['password']; password_verify($password_input , $data_array['password']);
see http://php.net/manual/de/function.password-verify.php
an of course, answer pid right, need user username instead password.
Comments
Post a Comment