Opened 7 weeks ago
Last modified 2 weeks ago
#66238 new enhancement
Users with "same" email address can be accidentally created
| Reported by: | flymike | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Login and Registration | Version: | 2.1 |
| Severity: | normal | Keywords: | has-patch has-screenshots changes-requested has-unit-tests |
| Cc: | Focuses: | administration |
Description
Wordpress does not permit multiple users with the same email address, using RFC 5321 to define the localpart of the address.
However, several major email service providers (Gmail, Outlook, Yahoo) ignore mixed case in localparts.
This means that WordPress will support 2 users with email addresses abc@… and ABc@… - although those 2 addresses represent the same mailbox.
Propose an enhancement:
- Warn admins when manually creating a user that the new email address might be a duplicate of...
- Highlight email addresses on the admin Users page that are case-insensitive identical.
Attachments (4)
Change History (18)
@
6 weeks ago
We changed subsriber emaill same as Admin email with uppercase name and without error updated.
#1
@
6 weeks ago
- Focuses administration added
- Keywords has-patch has-screenshots added
- Priority normal → high
- Severity normal → major
#2
in reply to: ↑ description
@
6 weeks ago
- Keywords changes-requested added
- Priority high → normal
- Severity major → normal
- Version 7.1.2 → 2.1
Replying to flymike:
However, several major email service providers (Gmail, Outlook, Yahoo) ignore mixed case in localparts.
I think the vast majority of email providers would ignore the casing. RFC 5321 indicates that it “may be case-sensitive”:
Local-part = Dot-string / Quoted-string
; MAY be case-sensitive
So this seems to imply that the default state is for it to not be case sensitive, which is reflected in this being the standard behavior.
So yes, I think this is valid.
@ravipatel Please open a pull request with your patch to make it easier to review and so that the automated checks in CI can run.
Tradeoff: the LOWER(user_email) lookups can't use the index.
This is a big tradeoff and it would probably be a non-starter for large multisite installs. In this case, perhaps the LOWER check should only be done in the cases where we know a case-insensitive collation isn't being used. Otherwise, a new table column could be added to store the lower-case version, but this may be excessive if the default is to use a case-insensitive collation (and therefore this seems a normal priority).
This ticket was mentioned in PR #14053 on WordPress/wordpress-develop by @ravipatel.
6 weeks ago
#3
- Keywords has-unit-tests added
Trac ticket: https://core.trac.wordpress.org/ticket/66238
What
email_exists() now matches emails case-insensitively regardless of the DB collation, so ABc@example.com can't be registered when abc@example.com exists. The Users list table flags existing case-variant duplicates so they can be cleaned up.
Index tradeoff (from Trac feedback)
The LOWER(user_email) lookup now only runs when the user_email column has a case-sensitive collation (*_bin, *_cs) or the collation can't be determined. With the default *_ci collation, the existing indexed lookup already ignores case, so no extra query is made.
The list table check only queries the email addresses on the current page, using user_email IN (...) on *_ci collations so the index is used.
Collation detection is cached per request in the private _wp_is_user_email_case_sensitive() and can be overridden with the wp_is_user_email_case_sensitive filter.
Testing
npm run test:php -- --group 66238(covers both the case-insensitive and case-sensitive paths).- Create a user
abc@example.com, then try to addABc@example.com: it should be rejected with "This email address is already registered".
#4
@
6 weeks ago
- Keywords has-unit-tests removed
@westonruter Thanks for the review! PR: https://github.com/WordPress/wordpress-develop/pull/14053
Following your suggestion, the LOWER() lookup now only runs when the user_email column's collation is case-sensitive (or unknown). On the default *_ci collations the existing indexed lookup already handles it, so there's no extra query and no index tradeoff. The users list table check was also reworked to only look up the emails on the current page, using the index on *_ci collations.
If a lower-case column is still preferred for case-sensitive installs, I'm happy to explore that in a follow-up.
@westonruter commented on PR #14053:
6 weeks ago
#5
Please add the AI disclosure to the PR description:
@ravipatel commented on PR #14053:
6 weeks ago
#6
Thanks @westonruter! Just a heads-up: my fork was created from another fork (ravikumarup/wordpress-develop) rather than directly from WordPress/wordpress-develop, so "Allow edits by maintainers" may not let you push to this branch. To avoid that, I've invited you as a collaborator on rvpatel/wordpress-develop. Once you accept the invitation, you should be able to push changes directly to the trac-66238 branch. I'll re-fork from the official repository once my open PRs are wrapped up.
@ravipatel commented on PR #14053:
6 weeks ago
#7
@westonruter The PR has been updated to address the review feedback: the LOWER() lookup now runs only when the user_email column uses a case-sensitive collation, so the default *_ci setup keeps using the index. It's also up to date with trunk and all checks pass. Ready for another review when you have time.
This ticket was mentioned in PR #14209 on WordPress/wordpress-develop by @ravipatel.
5 weeks ago
#8
- Keywords has-unit-tests added
Replaces #14053, which was opened from a nested fork. Previous review history is there.
What
email_exists() now matches emails case-insensitively regardless of the DB collation, so ABc@example.com can't be registered when abc@example.com exists. The Users list table flags existing case-variant duplicates so they can be cleaned up.
Index tradeoff (from Trac feedback)
The LOWER(user_email) lookup now only runs when the user_email column has a case-sensitive collation (*_bin, *_cs) or the collation can't be determined. With the default *_ci collation, the existing indexed lookup already ignores case, so no extra query is made.
The list table check only queries the email addresses on the current page, using user_email IN (...) on *_ci collations so the index is used.
Collation detection is cached per request in the private _wp_is_user_email_case_sensitive() and can be overridden with the wp_is_user_email_case_sensitive filter.
Testing
npm run test:php -- --group 66238(covers both the case-insensitive and case-sensitive paths, including a successfulLOWER()fallback when the exact lookup misses).- Create a user
abc@example.com, then try to addABc@example.com: it should be rejected with "This email address is already registered".
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Reworking the patch to address the Trac feedback (limiting the LOWER() lookup to case-sensitive collations), the list table query, PHPUnit tests, and running PHPCS/PHPUnit/PHPStan; also the latest review fixes. I reviewed and tested the final implementation and take responsibility for it.
@ravipatel commented on PR #14053:
5 weeks ago
#9
Comment on old #14053. It should already be closed automatically because you deleted the fork, but it still accepts comments
@ravipatel commented on PR #14053:
5 weeks ago
#10
#11
@
5 weeks ago
New PR: https://github.com/WordPress/wordpress-develop/pull/14209
@westonruter reviewed the earlier PR and the changes look good to him, but he suggested someone more familiar with the Users component take the review from here. Tests pass, and the case-sensitive fallback now has test coverage. Could a Users component maintainer take a look?
#12
@
5 weeks ago
Patch Testing Report
Patch Tested: https://github.com/WordPress/wordpress-develop/pull/14209
Environment
- WordPress: 7.2-alpha-63166-src
- PHP: 8.3.35
- Server: wordpress-develop local Docker environment (nginx), PHPUnit 9.6.38
- Database: MySQL 9.7.2 (
wp_users.user_emaildefaultutf8mb4_unicode_520_ci, and switched toutf8mb4_binfor testing) - Browser: N/A (WP-CLI and PHPUnit)
- OS: Windows 11 (Docker Desktop / WSL 2)
- Theme: N/A
- MU Plugins: None activated
- Plugins: None activated
Actual Results
- ✅
_cicollation:wp user createwithABc-TR@example.comwhenabc-tr@example.comexists is rejected (same as trunk, no regression). - ✅
utf8mb4_bincollation, trunk: the case-variant user is created (bug reproduced). - ✅
utf8mb4_bincollation, PR: creating the case-variant user is rejected with "Sorry, that email address is already used!". - ✅
utf8mb4_bincollation, PR:wp user updatechanging another user's email to a case variant is rejected. - ✅ Users list table: with two existing case-variant accounts, both rows show "Another user has this email address, possibly with different letter case." on both
_binand_cicollations; the unrelated admin row is not flagged.
Additional Notes
--group 66238: 10 tests pass on the PR (single site, multisite, and--order-by=reverse). With the PR's tests run against unpatchedsrc, 6 of 10 fail (3 errors, 3 failures), so the tests cover the change.--group user: passes on the PR (1359 tests); the 5 warnings are PHPUnit 10 deprecation notices that also appear on trunk.- Not tested: SQLite, and a visual check of the new list table CSS.
- AI assistance: Claude Code was used to run the tests and the WP-CLI checks; results reviewed by me.
Supplemental Artifacts
None
@westonruter commented on PR #14209:
5 weeks ago
#13
Per https://github.com/WordPress/wordpress-develop/pull/14053#pullrequestreview-5474743136:
The changes look good to me. But I don't have a lot of experience with users, so best if I let someone else pick this up the review from here.
@ravipatel commented on PR #14209:
2 weeks ago
#14
Behavior note: on a case-sensitive collation, a user can no longer change only the letter case of their own email on the profile screen: send_confirmation_on_profile_email() compares with !==, and email_exists() now finds the user's own account and reports it as already used. Default case-insensitive installs already behave this way, so this makes both kinds of install consistent.
On a default install, case-variant duplicates are already rejected, because wp_users.user_email uses a _ci collation. The issue appears with case-sensitive collations (*_bin), with SQLite, and with data created under WP_IMPORTING. This patch makes email_exists() case-insensitive regardless of collation and flags existing duplicates on the Users screen. Tradeoff: the LOWER(user_email) lookups can't use the index.