The Gmail Email Normalization Hack That Fixed My OAuth System
November 9, 2025 • Bojan
November 9, 2025 • Bojan

It started as a random login mismatch that made no sense.
Same user. Same Google account. Different results.
Two sign-ins with the same Gmail somehow created two different accounts in WordPress Multisite.
OAuth wasn’t broken – my email matching logic was.
Gmail quietly ignores dots and plus signs in the local part of an address.
That means all of these are the same account:
[email protected]
[email protected]
[email protected]
[email protected]
But WordPress (and most databases) treat them as four separate users.
So when a user signs in with Google using [email protected], WordPress checks for that exact string.
No match → new user → duplicate account.
Suddenly your “sign in with Google” button can fracture your user base.
Instead of comparing raw emails, normalize them first.
/**
* Normalize email for consistent OAuth matching
*/
function normalize_email($email) {
$email = strtolower(trim($email));
if (!str_contains($email, '@')) return $email;
[$local, $domain] = explode('@', $email, 2);
// Strip "+tag"
if (($pos = strpos($local, '+')) !== false) {
$local = substr($local, 0, $pos);
}
// Remove dots for Gmail accounts
if (in_array($domain, ['gmail.com', 'googlemail.com'], true)) {
$local = str_replace('.', '', $local);
}
return $local . '@' . $domain;
}
Now Gmail addresses normalize cleanly:
[email protected] → [email protected]
One user, one account, no duplicates.
It’s five lines of logic that fixed what could have become a nightmare later.
This is one of those bugs that hides behind “everything works fine” until scale.
You won’t notice it in development – you’ll notice it when customers start saying,
“I signed in with Google and now I have two dashboards.”
This single normalization step ensures:
The normalization hack is just one layer of a bigger authentication system I built for a multi-tenant WordPress SaaS.
sso.samplehq.io to log users directly into their workspace on company.samplehq.io.The Gmail normalization might look like a tiny helper function,
but it’s part of a larger philosophy: make every assumption explicit before launch.
This five-line “Gmail normalization hack” isn’t just about cleaner code.
It’s about thinking like a system – not a script.
When you understand how identity works across providers,
you stop reacting to bugs and start engineering around them.
Most developers will never notice this issue until it burns them.
You can fix it right now – and never think about it again.

I’m Bojan Josifoski - I’m a WordPress systems engineer who developed and maintained a proprietary WordPress-based framework used by U.S. financial institutions between 2016 and 2025.