#17561: EmailField does not automatically lower the case in email addresses
-------------------------------------+-------------------------------------
Reporter: zechs.marquie@… | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 1.3
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: EmailField, | Triage Stage:
duplicates | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by jlherren):
This is an old ticket, but since it rates very high on Google I'd like to
describe another solution that I have been using and that works great.
The relevant RFCs clearly state that the local-part of the email address
is case-sensitive, yet it is still true that many (but not all) email
providers operate in a case-insensitive manner. The problem that results
is that it allows users to register multiple accounts to my site using
various capitalization of their one and the same email address; for
example they can register ''ME@examplecom'' as well as ''me@examplecom''.
This is something that I do not want to allow and I suppose I might not be
alone with this.
The obvious and simple solution of lower-casing all user input is
'''not''' satisfactory to me. I believe that the user's choice of how to
capitalize his/her email address should be respected and I wish to not
alter it.
My solution involves a field 'normalized_email' which lower-cases the
email (or applies other transformations) as well as an 'original_email'
field, which stores the original user input. For identification purposes
(login, registration, duplicate check) I use the normalized email, but for
display and email sending purposes I use the original email.
To make all of this work quite some extra code is necessary. Since my code
is very project specific and it's too long anyway, I can't post it here.
But here's a quick summary: A method UserManager.normalize_email() will
take care of the normalizing transformation. Overriding User.save() will
make sure to always set normalized_email to
UserManager.normalize_email(original_email) prior to saving to the
database. All forms (login form, registration form, user editing forms,
admin forms) will have to verify user input and check for duplicate
normalized emails manually.
On a side note: Some email providers are insensitive to more than just the
capitalization. For example, Gmail will ignore all dots in the email,
making john@gmailcom the same as j.o.h.n@gmailcom. To prevent the same
email address to be used for multiple accounts, further normalization is
possible.
--
Ticket URL: <https://code.djangoproject.com/ticket/17561#comment:9>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/081.96b8923caf4ab2f37cfdd6cc490ac4b6%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.