I'm setting up a very basic login page using php, but for some reason, no matter what username or password I put in, it automatically takes me to the logged in page(Home Page). Even if that particular username/password isn't even registered in the database.
I feel like the fact that I copied some of the code from the register page might've been my downfall.
//log user in from the login Page
if (isset($_POST['login'])) {
if (empty($_POST['username'])) {
array_push($errors, "Username is required");
}
if (empty($_POST['password'])) {
array_push($errors, "Password is required");
}
if (count($errors) == 0) {
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
$query = "SELECT * FROM users WHERE username = '$username' AND password = '$password'";
// log user in
$_SESSION['username'] = $username;
$_SESSION['success'] = "You are now logged in";
header('location: index.php'); //redirect to home page
}else {
array_push($errors, "The username/password combination is incorrect");
}
}