I am getting an Invalid Password error when I try to execute my code. I want to mention that I am using the same PASSWORD_BCRYPT function for signup too. But, when I implement it in the login code I am not getting success. Please tell me what am I doing wrong and help me fix the bug.
Another thing is that I am entering the same/correct password I used during registration for the demo user. Here is the code for login.
if(isset($_POST['login'])){
$user_name = ($_POST['user_name']);
$upassword = password_hash($_POST['password'], PASSWORD_BCRYPT);
$statement = $db->prepare("SELECT user_name, password, status FROM user_registration WHERE user_name = ?");
$statement->bind_param('s', $user_name);
$statement->execute();
$statement->bind_result($user_name, $password, $status);
$row = $statement->fetch(); //fetch DB results
if (!empty($row)) { // checks if the user actually exists(true/false returned)
if (password_verify($upassword, $row['password'])) {
echo 'Password is valid!';
} else {
echo 'Invalid password.';
}
} else {
echo "Entered data is invalid."; // User login details entered does not match any in DB
}
$statement->close();
}