I'm having an issue getting password_verify
to validate the password.
I have the password stored in the database using
password_hash($password, PASSWORD_DEFAULT)
On the login page, I have the user enter their username and password and retrieve the input via the post method $_POST['pwd']
(which is the user's input for the password).
I then retrieve the hashed password from the database and check it against the password from the login
if(password_verify($password, $results['password']))
I can't seem to figure out why the password never seems to match. I've read filter/escape can affect password_verify()
and changed that as well and got the same result. Any help would be appreciated.
<?PHP
include('connection.php');
if(isset($_POST['submit'])){
$username = trim(filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING));
$password = trim(filter_input(INPUT_POST, 'pwd', FILTER_SANITIZE_STRING));
$sql = $db->query("SELECT password FROM users WHERE username = '$username'");
$results = $sql->fetch(PDO::FETCH_ASSOC);
$savedHash = $results['password'];
//echo $savedHash;
if(password_verify($password, $savedhash)){
echo "yes " . $password;
}else{
echo "no";
}
?>