I use password_hash() standard method from PHP5, and I understand it generates different hash value for each run.
Refer to this: correct use of password_hash
The question is, if I store the hashed password into my database (MySQL), how do I check if the user entered the correct password in the login page?
In my signup.php, I have something like:
include 'PasswordHash.php' // contains various standard methods
$submitted_password = password_hash($_POST['password'], PASSWORD_BCRYPT);
and
$add = mysqli_query($connection, "INSERT INTO `users` VALUES(NULL,'$submitted_username','$submitted_email','$submitted_password')");
and in my login.php, I have:
$submitted_password = $_POST['password'];
$hashed_password = password_hash($_POST['password'],PASSWORD_BCRYPT);
and
if (password_verify($submitted_password, $hashed_password)) {
echo "<script type='text/javascript'>alert('$pass');</script>";
} else {
echo "<script type='text/javascript'>alert('$fail');</script>";
}
This will obviously echo PASS because login.php will hash the password once and compare them, but if I try
echo $hashed_password;
, it is completely different from what I have in the database, obviously because it will generate different salt and use it to hash.
FINAL QUESTION: Then, how do I check if the user entered the correct password when user submitted password will be hashed into different values every single time?
I don't know if you can understand this question.. I just don't know how to describe this better.
Thank you in advance.