ACC-4Required
Compare email addresses and usernames in one canonical form
Store each email address and username as typed, plus one canonical key. Look up, compare and enforce uniqueness on the key only.
How to do it
For an email, trim spaces, apply Unicode NFC, lowercase the domain and convert it with IDNA under UTS #46. That is domainToASCII in Node.js and the idna package in Python, not Python's built-in idna codec, which follows the older IDNA 2003. Lowercase the local part too, because almost every mail provider ignores its case. Never remove dots or +tags, because only some providers ignore them. For a username, apply the PRECIS UsernameCaseMapped profile from RFC 8265, which folds case and width. Put the unique index on the key. Send mail to the address as typed. International addresses covers mailboxes with non-ASCII letters.
Examples
JavaScript example
import { domainToASCII } from 'node:url';
export function emailKey(typed) {
const address = typed.trim().normalize('NFC');
const at = address.lastIndexOf('@');
const local = address.slice(0, at).toLowerCase();
const domain = domainToASCII(address.slice(at + 1).toLowerCase());
return `${local}@${domain}`;
}
Python example
import unicodedata
import idna
def email_key(typed: str) -> str:
address = unicodedata.normalize("NFC", typed.strip())
local, _, domain = address.rpartition("@")
return f"{local.lower()}@{idna.encode(domain, uts46=True).decode('ascii')}"
SQL example
CREATE UNIQUE INDEX users_email_key ON users (email_key);
How to check
Sign up as Anna@Example.com, then as anna@EXAMPLE.com. The second finds the first account. Sign up as anna+shop@example.com, and it creates a separate account.
Sources
Related rules
- EML-6 Accept international addresses in Email
- TNS-13 Spot banned people who sign up again in Trust and safety
- LOC-29 Change the case of identifiers without a locale in Localization
- ECM-11 Let guests check out without an account in E-commerce and fulfilment
- ECM-37 Limit each coupon per customer instead of per account in E-commerce and fulfilment
- APS-15 Trust an email domain only after strict parsing in Application security
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/accounts/sign-up/identifier-normalisation">Agent Wranglers accounts and identity playbook</a>. In code you write, add a comment next to it with the same link.