I am trying to match and verify the password user has input via $_POST and the hashed password in database. The problem is that when I hash the input password, BCRYPT produces a new hash each time meaning no two hashes will be the same which will give me no match. How can I possibly match BCRYPT hashed passwords? Thank you for any help!
LOGIN:
$password = password_hash(htmlentities($_POST['password']), PASSWORD_BCRYPT, array(
'cost'=>14));
$stmt = $mcon->prepare("SELECT `password` FROM members WHERE password=:password");
$stmt->bindParam(":password", $password);
$stmt->execute();
//get_result
$data_array = $stmt->fetch(PDO::FETCH_ASSOC);
//echo passwords
echo 'Password from form: ' . $password . '<br />';
echo 'Password from 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 and $hashedpassword match then start session
$stmt->close();
$mcon->close();