This topic is locked

Dual login

5/31/2021 3:51:13 AM
PHPRunner General questions
P
pinoyoutdoor author

Is it possible in login page to use both either username and email as USERAME in login page? how if possible?

admin 5/31/2021

We do not have this kind of functinality right now. It should be possible with the help of some custom coding.

You can implement BeforeLogin event where you can craft your own SQL statements to validate what user entered against the database. If it passes the check you can use Security::loginAs() to log the user in and redirect them to the landing page.

HJB 6/1/2021

Login with username OR e-mail address

... for inspiration purposes only ...

P.S. W3lessons - Same headline

P
pinoyoutdoor author 6/3/2021

thanks for guide...hopefully I can be succesfull....

A
acpan 6/3/2021

I did this before, using the PHPRunner's Security API and DB API as what mentioned by admin.

Here's the sample code, assuming, user table has fields: user_id, password, email.
Choose user_id (or email) and password as the login credentials at PHPR Security menu.

Then before login successful event:

// $username is PHPRunner's system varaible that captures what user enters
// on the login form. It can be user_id or email, assign to $temp

$temp = $username;
// check against the user table
$rs = DB::Query("SELECT user_id, email FROM user_table WHERE ( user_id = '$temp' OR email='$temp') AND password = '$password' limit 0,1);
while( $record = $rs->fetchAssoc() )
{
// Found! so use Security API to log user in with user_id (use email if you choose email at sercurity credential),
// and run the after sucessful login event with the true flag.
Security::loginAs($record["user_id"], true);
// if you want to skip the after sucessful login event, set the flag above to false, and do redirect to menu:
// header('Location: menu.php');
}
}

// if the flow reach here, there was no match, let program take over with normal unsucessful login error.

I have simplified a little to aid your understanding, my original version have a few more lines that deals with password matching with bycrypt

hope it helps.