I have a password being hashed and saved in to a SQL database with the following code:
$passHash = password_hash($password, PASSWORD_DEFAULT);
It is saved in to a field called 'password' with the type VARCHAR(255)
I then use the following code to log the user in
$dbconn = OpenCon();
$username = $_POST['usernameInput'];
$password = $_POST['passInput'];
$passHash = password_hash($password, PASSWORD_DEFAULT);
$school = $_POST['schoolInput'];
$sqlstmnt2 = 'SELECT * FROM users WHERE username = :username AND school = :school';
$stmtUsr2 = $dbconn -> prepare($sqlstmnt2);
$stmtUsr2 -> bindValue(':username', $username);
$stmtUsr2 -> bindValue(':school', $school);
$stmtUsr2 -> execute();
$rows = $stmtUsr2 -> fetchAll();
$n = count($rows);
if($n<1 or !password_verify($rows[0]['password'], $passhash)) {
echo 'No user account exists. Please check your credentials'."<br>";
}
else{
$_SESSION['username'] = $username;
header("Location: home.php");
}
When I run it and enter a details I know to be correct, the password_verify function is not returning that they are the same. What am I doing wrong?