0

Here is the line that the error is coming from...

If (password_verify($password, $user['password'])){}

Here is what's inside this of statement...

    $_SESSION['id'] = $user['id']; 
    $_SESSION['username'] = $user['username']; 
    $_SESSION['email'] = $user['email']; 
    $_SESSION['verified'] = $user['verified']; 
    $_SESSION['message'] = "Success!"; 
    $_SESSION['alert-class'] = "alert-success"; 
    header ('location: verification.php'); 
    exit(); 
} else { 
    $errors['login_fail'] = "Incorrect Username or Password"; 
} 
4
  • The error occurs whenever i attempt to enter both a username and password combination that does not exist in the database. Commented Apr 28, 2020 at 20:37
  • I assume you did $user = some_fetch(); or something which is returning null because no rows in DB. Show more code. Commented Apr 28, 2020 at 20:43
  • I did $user = $result->fetch_assoc(); Commented Apr 28, 2020 at 20:46
  • And what's your question? What have you tried to debug this problem? Commented Apr 28, 2020 at 20:57

1 Answer 1

1

You need to check if you've managed to load the user from DB. It looks like the function that is loading data from DB returns null when the user is not found.

You can change your condition to something like this:

if(!empty($user) && password_verify($password, $user['password'])) {
  // ... log in user
} else {
  // ... do something when password or user doesn't match
}
Sign up to request clarification or add additional context in comments.

1 Comment

I apologize, first time using this platform.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.