I'm creating a site where a user can login. When they make an account, I save the hashed password in the database. I am trying to user password_verify() in order to confirm the password matches, but it returns false.
To confirm that they match, I print out both the hashed version of what the user typed in and the hashed password that is stored in the database. I know a common problem is that the database password field is too small for the hashed password, but I have tried setting it as both VARCHAR(256) and TEXT to make sure the entire hashed password is stored.
if(isset($_POST['email'])){
$email = strip_tags(mysqli_real_escape_string($conn, $_POST['email']));
$password = strip_tags(mysqli_real_escape_string($conn, $_POST['passwd']));
$sql = "SELECT email, passwd AS hashed_password FROM Accounts WHERE email = '$email'";
$result = $conn->query($sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
//print the hashed password that is stored in the database
echo 'stored in the database: '. $row['hashed_password']. '<br>';
$hash = hash('sha512', $password);
//print the hashed version of what the user typed in
echo 'hashed version of what your submitted: '. $hash. '<br>';
if( password_verify($password, $hash)){
echo "true";
}
else{
echo 'false';
}
I expect that password_verify() returns true but it returns false
Here is what i have it currently outputting:
stored in the database: 1f40fc92da241694750979ee6cf582f2d5d7d28e18335de05abc54d0560e0f5302860c652bf08d560252aa5e74210546f369fbbbce8c12cfc7957b2652fe9a75
hashed version of what your submitted: 1f40fc92da241694750979ee6cf582f2d5d7d28e18335de05abc54d0560e0f5302860c652bf08d560252aa5e74210546f369fbbbce8c12cfc7957b2652fe9a75
false