I hash password before it is store into DB. When I want to get it back and compare with user input I always get "password does not match". I tried a lot of fixes but nothing seems to work. May be the problem is with my syntax, I am not good with php.
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
if (password_verify($RegisteredPass, $row['pass']))
{
echo "tchd";
echo "ID:".$row['id'] ."|Name:".$row['name']. "|User:".$row['user'];
}
else{
echo "pass doesn`t match";
}
}
} else {
echo "user not found";
}
Hashing password
$hassedPassword = password_hash($password, PASSWORD_DEFAULT, ['cost' => 12]);
I am not very concern about security, because it is just for a project. I just need to make it work.
Edit
I changed while loop as was in "duplicate", but it still does not work. Any ideas why?
$sql = "SELECT pass, id, name, user FROM unityTut WHERE user='".$RegisterUser."'";
$result = $conn->query($sql);
if ($result->num_rows === 1) {
$row = $result->fetch_array(MYSQLI_ASSOC);
if (password_verify($RegisteredPass, $row['pass'])) {
//Password matches, so create the session
echo "Match";
}else{
echo "The username or password do not match";
}