27

In this example, Django talks about normalizing an email address with self.normalize_email(email) where self is BaseUserManager. When I search for "normalizing emails" it seems to be a practice across all platforms. I see tutorials of how to do it, but nothing really explaining what it is and what it's used for.

2 Answers 2

49

For email addresses, [email protected] and [email protected] are equivalent; the domain part is case-insensitive according to the RFC specs. Normalizing means providing a canonical representation, so that any two equivalent email strings normalize to the same thing.

The comments on the Django method explain:

Normalize the email address by lowercasing the domain part of it.

10

One application of normalizing emails is to prevent multiple signups. If your application lets the public to sign up, your application might attract the "unkind" types, and they could attempt to sign up multiple times with the same email address by mixing symbols, upper and lower cases to make variants of the same email address.

From Django's repository, the docstring of normalize_email is the following:

Normalize the email address by lowercasing the domain part of it.

What this method does is to lowercase the domain part of an email, so this part is case insensitive, so consider the following examples:

>>> from django.contrib.auth.models import BaseUserManager
>>> BaseUserManager.normalize_email("[email protected]")
[email protected]
>>> BaseUserManager.normalize_email("[email protected]")
[email protected]
>>> BaseUserManager.normalize_email("[email protected]")
[email protected]
>>> BaseUserManager.normalize_email("[email protected]")
[email protected]
>>> BaseUserManager.normalize_email("[email protected]")
[email protected]

As you can see all emails are equivalent because the case after @ is irrelevant.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.