Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

May I safely treat email addresses lower case?

In theory emails are case sensitive. But using emails as system login I want them to be all lower case (i.e. [email protected] and [email protected] cannot be different users).

Can this be a problem for some users who use case sensitivity in their email address? Does somebody use it out there?

Edit: Because there are many "preserve case on save, ignore on login" answers: This system would break if I really had two different users john@smith and John@smith, wouldn't it?

Example: john@smith and John@smith have the password 123. How do I know which one just authenticated?

like image 588
Jakob Stoeck Avatar asked Oct 01 '09 11:10

Jakob Stoeck


People also ask

Should email addresses be in lower case?

If you're wondering, “do capital letters matter in email addresses?”, the simple answer here is no. Capitals don't really matter in email addresses. They aren't case-sensitive, unlike passwords. That's because modern mail servers essentially ignore capital letters.

Does it matter if you use lower or upper case in email address?

So, Are Emails Case Sensitive? No. Email addresses are not case sensitive. If your email address is [email protected] but someone enters it in all lowercase letters, you're still going to receive the email.

Do emails have to be case sensitive?

No, email addresses are not case sensitive. Whether you enter an email like this “[email protected]”, like this “[email protected]”, or like this “[email protected]”, it doesn't make an iota of difference.

Why are email addresses not case sensitive?

Yes, according to RFC 5321, the local part is case sensitive. However, Email Service Providers (ESPs) widely recognize that allowing upper case letters can lead to unnecessary confusion. That's why most ESPs limit the options available to users when creating an email address.


2 Answers

Don't throw away data. Store the email address or username exactly as you received it, with the exception of trimming both ends of the string.

When sending email, use the case that was supplied by the user. Just because case-sensitivity is rare is no reason to not handle it - otherwise that user gets no mail, and can possibly not even register.

When authenticating a user, you can optionally do a compare on lower case (or upper case) strings, so that the case is disregarded.

So, by preserving the user input data you have suddenly given yourself options: whether to do case-sensitive compares on authentication, and whether to use case-sensitive email addresses when sending mail. Even if you don't choose to avail yourself of them now, the purpose of preserving data is to allow you (or some other developer) to have those choices down the road.

like image 68
D'Arcy Rittich Avatar answered Sep 17 '22 15:09

D'Arcy Rittich


According to RFC 2821:

The local-part of a mailbox MUST BE treated as case sensitive. Therefore, SMTP implementations MUST take care to preserve the case of mailbox local-parts. Mailbox domains are not case sensitive. In particular, for some hosts the user "smith" is different from the user "Smith". However, exploiting the case sensitivity of mailbox local-parts impedes interoperability and is discouraged.

So, while you can treat emails addresses with case sensitivity, you are discouraged from doing so.

like image 22
Pete OHanlon Avatar answered Sep 21 '22 15:09

Pete OHanlon