I upgraded my server to PHP 8 and now when I login without a valid username I get
Warning: Trying to access array offset on value of type null in"
If I understand correctly it's due to PHP now catching this issue and old versions didn't pick it up. I have to be honest and say this is out of my league so I'm hoping someone can help adjust the code. According to the error it's on line 117 which is
if (password_verify($password, $user['password']))
Full code is below for the section if you need anything else let me know.
// CHECK IF DETAILS ENTERED ARE VALID (VALIDATION!)
if (empty($username)) {
$errors['username'] = "Username required";
}
if (empty($password)) {
$errors['password'] = "Password required";
}
if (count($errors) === 0) {
$sql = "SELECT * FROM users WHERE email=? OR username=? LIMIT 1";
$stmt = $conn->prepare($sql);
$stmt->bind_param('ss', $username, $username,);
$stmt->execute();
$result = $stmt->get_result();
$user = $result->fetch_assoc();
if (password_verify($password, $user['password'])) {
// LOGIN SUCCESS
$_SESSION['id'] = $user['id'];
$_SESSION['username'] = $user['username'];
$_SESSION['email'] = $user['email'];
$_SESSION['verified'] = $user['verified'];
// SET USER MESSAGE ON HOME PAGE
$_SESSION['message'] = "You are now logged in";
$_SESSION['alert-class'] = "alert-success";
header('location: index.php');
exit(0);
} else {
$errors['login_fail'] = "Sorry wrong credentials";
}
}