This topic is locked
[SOLVED]

Only allow login for Active Users

9/26/2024 1:39:01 PM
PHPRunner General questions
A
asawyer13 authorDevClub member

I feel like I should know this, but guess not.

I have a Active tinyint in my user table.

When a user goes to login, not only does the login id and password have to be correct, but I only want to allow them to login if the Active field is a 1.

If that's not easy, I guess I could let them login and then on the on successful login, display a message and then log them out.. I don't know how to do that however.

Thanks in advance,
Alan

W
WilliamBDevClub member 9/26/2024

You could change login page event "Before login" and add this.Change the sql as needed to fit your table.

$sql = DB::PrepareSQL("select active from usersTable where username=':1'",$username);
$isActive = DB::DBLookup($sql);

if($isActive)
return true;
else {
$message = "You cannot login as you are not an active user";
return false;
}
G
Grdimitris 9/26/2024

As Sergei said long time ago, in query add where active=1

A
asawyer13 authorDevClub member 9/26/2024

Thanks
I like both options. Very useful.