i have a problem with a login script on my site, the script works after a user registers it will allow the user to login, but after some time like an hour or more the script will denied the user access to login by saying incorrect login details (this error appears when the user password is incorrect) but in this case the password is correct, i have tried to understand the reason for this kind of problem.
Again when the user recovers the password and uses it to login it will login. Please i need some help below is the code for the login
<?php
if (isset($_POST['loginaccount'])) {
$usernamefor = $_POST['usernamelogin'];
$passwordfor = $_POST['passwordlogin'];
$username = mysqli_real_escape_string($connect, $usernamefor);
$pass = mysqli_real_escape_string($connect, $passwordfor);
$query = "SELECT * FROM users WHERE username = '{$usernamefor}' ";
$query = mysqli_query($connect, $query);
$count = mysqli_num_rows($query);
if (!$query) {
die("QUERY FAILED". mysqli_error($connect));
}
if ($count <= 0) {
$error1 = "<div class='danger'><a href='#' class='close' data-dismiss='alert' aria-label='close'>×</a>Sorry you are not a registered user </div>";
} else {
while ($row = mysqli_fetch_array($query)) {
$id = $row['id'];
$username = $row['username'];
$user_password = $row['password'];
}
$passwordloader = crypt($pass, $user_password);
if ($username == $username && $passwordloader == $user_password) {
header("Location: the users dasboard");
// the below set various sessions for users//
$_SESSION['id'] = $id;
} else {
$error2 = "<div class='danger'><a href='#' class='close' data-dismiss='alert' aria-label='close'>×</a>Sorry your login details in incorect</div>";
}
}
}