-
Notifications
You must be signed in to change notification settings - Fork 684
Open
Labels
Description
What happened?
Description
I'm seeing an issue where a user can't log in with their username, if there's another user that has a different username, but the same e-mail. Even if that other user is disabled.
Steps to reproduce
- Set
useEmailAsUsernametofalseinconfig/general.php. - Create a user with username
info@example.comand E-Mailinfo@example.com. Activate the user. - Create another user with username
boband usernameinfo@example.com. Leave it deactivated. - Try to log in with
info@example.com. It may work or it may not, because the database may return either user (there's nothing in the query to order the users, so it's up to the database).
This may seem like a contrived example, but we're seeing this in the real world. In this case, the e-mail is a shared mailbox and the users are synced from an external system.
Expected behavior
I suggest two changes (ideally, I would like to see both implemented):
- If
useEmailAsUsernameis set tofalse, theusernameshould always take precedence over theemailfield. That is, if a user tries to log in, the system should check if there's a match in theusernamefield before checking matches in theemailfield. - If two or more accounts have the same email, but one is disabled, the login should always favor the account that is enabled.
Actual behavior
The query in User::getUserByUsernameOrEmail() just tries to find any user where the username or email match the input, so the login may or may not work.
Craft CMS version
5.8.18
PHP version
No response
Operating system and version
No response
Database type and version
No response
Image driver and version
No response