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.
Name Normalization analyzes email document headers to identify all aliases (proper names, email addresses, etc.) and the entities (person, distribution group, etc.) those aliases belong to. Name normalization automatically merges entities with those created by Legal Hold, Processing, or Case Dynamics.
It is best to standardize your addresses first, because duplicates will be much easier to spot and confirm. Without standardizing addresses first, it will be difficult to tell if addresses are in fact duplicates. However, with address normalization complete, it is extremely easy to find the duplicates.
There are two main objectives of the normalization process: eliminate redundant data (storing the same data in more than one table) and ensure data dependencies make sense (only storing related data in a table).
Normalizing the amplitude of a signal is to change the amplitude to meet a particular criterion. One type of normalization is to change the amplitude such that the signal's peak magnitude equals a specified level. By convention in Matlab, the amplitude of an audio signal can span a range between -1 and +1.
For email addresses, foo@bar.com
and foo@BAR.com
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.
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("user@example.com")
user@example.com
>>> BaseUserManager.normalize_email("user@EXAMPLE.COM")
user@example.com
>>> BaseUserManager.normalize_email("user@example.COM")
user@example.com
>>> BaseUserManager.normalize_email("user@EXAMPLE.com")
user@example.com
>>> BaseUserManager.normalize_email("user@ExAmPlE.CoM")
user@example.com
As you can see all emails are equivalent because the case after @
is irrelevant.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With