I currently have a login function which works fine however i'm looking to add something into the function so it also checks if the users status is 1
.
1
= banned
0
= unbanned
function:
public function doLogin($uname,$umail,$upass)
{
try
{
$stmt = $this->conn->prepare("SELECT user_id, user_name, user_email, user_pass, status FROM users WHERE user_name=:uname OR user_email=:umail ");
$stmt->execute(array(':uname'=>$uname, ':umail'=>$umail));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
if($stmt->rowCount() == 1)
{
if(password_verify($upass, $userRow['user_pass']))
{
$_SESSION['user_session'] = $userRow['user_id'];
return true;
}
else
{
return false;
}
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
login.php
if(isset($_POST['btn-login']))
{
$uname = strip_tags($_POST['txt_uname_email']);
$umail = strip_tags($_POST['txt_uname_email']);
$upass = strip_tags($_POST['txt_password']);
if(empty($uname) || empty($umail) || empty($upass)){
$error = "Please enter all fields";
}
if($login->doLogin($uname,$umail,$upass))
{
$success = "Logged in successfully, redirecting..";
header( "refresh:3;url=debits" );
//$login->redirect('debits');
}
else
{
$error = "Incorrect username or password";
}
}
I tried doing if(password_verify($upass, $userRow['user_pass']) && $userRow['status'] == 0)
and I think this works however when I try testing with a banned account, I still receive the error message Incorrect username or password
when i'd prefer this to be Your account has been banned
.