How to login with an Email field or Username field using Security Identify

If my registration form let users sign up by entering (email, username, and password) I want to allow a user to be able to login using that email field or username field when they want to login. Has anyone ever implement that flow before. Currently Security Provider does not allow multiply Identity value like email, username in the Identity field.

You would just need to run a query before hand looking for either the username/email and then use the email produced from that query as the username for Sec Provider

Thanks for your reply @bpj So I have this setup based on your advice how do I handle the Security Login which is what from my understanding is the thing that actually log user in? Can you give me some sceenshot if you have one

In the login step, rather than pointing the username to $_POST.email, point it to the email address found in the query you created.

The security provider setup stays as it was from your first screenshot (withe the username pointing to the user table’s email field.

What you are doing is getting the $_POST from the form, using that for a query to match it with either the username or email (or mobile number etc…) and using the email address from the record that was found as the username to log in with.

Got it! lol and why didn’t I thought of that haha! Thanks I’ll try that now.

1 Like

Just tried what you suggested and that did not worked because the security provider is only recognizing the Identity that was given in the Users & Permissions step, so from my login form I have to enter what I define in the Security Provider which was the email.

In the login properties, point the username field to the email from the query before it (rather than the $_POST field)

Will this help?

And just to complement, the Database Single Query condition is missing an OR condition:

username equal $_POST.username
OR
email equal $_POST.username

Guys thanks a lot for your help. At @bpj your flow worked as it turns out for the reason it wasn’t working initially is because I forgot to update the Database Single Query condition to match the $_POST value so they matched as email to $_POST and usename to the same $_POST. At the time when I was getting the error the query filter did not had the username matching so it wasn’t returning any data if that used. For those who might come up on this setup here are some image to go with the instructions.



image

2 Likes