Background
Gmail allows '.'s and +filters allowing for an infinite number of email addresses all pointing to the same gmail account.
i.e. the following all point to the same gmail account:
Problem
We have a table on our production environment that hold all registered user's data including their email address.
Currently the gmail email addresses on this table contain a mix of the the above variations.
- Problem 1 - If the user tries to log back in, after they have created their account ,using their a different variation of his email address than we have on record this user will not be found.
- Problem 2 - The user is able to create different accounts on out site using the many variations of gmail email address.
Possible solutions:
One proposed solution would be to create a function...
CREATE FUNCTION STANDARDIZE_EMAIL (
@Email varchar(255)
)
RETURNS varchar(255)
AS
BEGIN
-- we make the email lowercase since email addresses are
-- case independent
SET @Email = LOWER(@Email)
-- if it is a gmail email address then we remove periods and filters from the username
IF RIGHT(RTRIM(@Email), 10) = '@gmail.com'
BEGIN
-- remove domain
SET @Email = REPLACE(@Email, '@gmail.com', '')
--remove periods from username
SET @Email = REPLACE(@Email, '.', '')
-- remove '+' and filter
IF CHARINDEX('+', @Email) > 0
SET @Email = SUBSTRING(@Email, 0, CHARINDEX('+', @Email))
-- add back the domain
SET @Email = @Email + '@gmail.com'
END
RETURN (@Email)
END
Example use:
SELECT * FROM table
WHERE STANDARDIZE_EMAIL(Email) = STANDARDIZE_EMAIL(@Email)
inb4: Running a process to standardize all the emails currently on the table is not an option as there could be duplicates, and users would lose the gmail +filter functionality
Is standardizing the email address on every record as we search through too expensive on the db?
Another proposed solution is to add a GmailEmail field to the table, and upon registering the user for the first time save a copy of the standardized version of his gmail email address to this second field which can be used for comparisons when they log back in.
Id rather not have to go to this extent if possible.