Here is the code for my password handler
protected function passwordMatch($username, $password)
{
$sql = 'SELECT `username`, `password` FROM `profile` WHERE `username` = ?';
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$username]);
$result = $stmt->fetch();
if (password_verify($result['password'], $password)) {
return true;
}
return false;
}
if ($this->passwordMatch($this->username, $this->password) !== true) {
$_SESSION['error'] = 'Password not matching';
header('Location: ../login.php');
exit();
}
Expecting: User would be logged on if username & password matches
Try: I tried changing from !==
to ===
to see if that is going to fix the issue, but it would log the user in even if password not matching each other, otherwise I could not tell what is wrong with my code
If you want to see full code here: https://github.com/sammo-2000/login
2
Answers
Maybe it’s because you are hashing the password in the
password_hash
before comparing?I have checked your github source code.
First of all, you have to extend your password length field in db.
Then please use password_verify() function.