Am trying to match the hashed password stored in the database with the login post password by using md5 for hashing ,but its always giving me incorrect password even when the hashed password is the exact been entered on the login page,cant seem to find where am going wrong.
This is how am hashing the user password on register page and then stored in the database
$password = $_POST['password'];
$hash= md5($password);
This is how am trying to verify if the hashed password
in the database is matching the login hashed password
// Escape email to protect against SQL injections
$email = $mysqli->escape_string($_POST['email']);
$password =$_POST['password'];
$hash = md5($password);
$result = $mysqli->query("SELECT * FROM `Agent` WHERE `email`='$email'");
$row = mysql_fetch_row($result);
$db_hash = $row['password'];
if( $db_hash !== $hash )
{
$_SESSION['message'] = "user with that email doesn't exist!";
echo"<script>alert('User login credentials are incorrect..!')</script>";
}
else
{
// User exists
$_SESSION['email'] = $user['email'];
$_SESSION['fname'] = $user['fname'];
$_SESSION['lname'] = $user['lname'];
$_SESSION['cell'] = $user['cell'];
$_SESSION['Agency'] = $user['Agency'];
header("location: Myprofile.php");
}
?>