Closed bmamlin closed 2 weeks ago
When validating the login, we attempt to login using the username and password. If it fails, assume the username is an email address and try to find a person with that email. If a person is found with that email, get the username for that person and use it to log them in
When validating the login, we attempt to login using the username and password. If it fails, assume the username is an email address and try to find a person with that email. If a person is found with that email, get the username for that person and use it to log them in
Why try to log in with an email address? Usernames should never contain an at-sign and emails will always contain an at-sign, so username.contains("@")
should reliably distinguish between email and non-email entries.
Wouldn't something like this work just before authentication?
if (username.contains("@")) {
// returns original string if no user is found with given email address
username = userWithEmailAddress(username);
}
Yeah, I thought about that, and it's clever and simple, but I wanted a more general solution
In the CustomLoginPageController, before authenticating, we could check if the username contains an at sign (@) and, if so, search (case-insensitively) for a matching email address and, if found, substitute the associated username before authenticating.