devise icon indicating copy to clipboard operation
devise copied to clipboard

Email validation should not be case-sensitive

Open jhilden opened this issue 16 years ago • 8 comments

When you try to add a new user with an email address that already exists in the database (e.g. [email protected]) but is spelled with a different case (e.g. [email protected]) it is not detected by the validations. Since email addresses are always not case-sensitive, devise should honor that.

See also here: http://groups.google.com/group/plataformatec-devise/browse_thread/thread/da5299872c2ea280?pli=1

Rails: 3.0.0.rc Devise: 1.1.rc2

jhilden avatar Aug 16 '10 13:08 jhilden

It already works this way in latest Devise (1.1.0).

josevalim avatar Aug 16 '10 13:08 josevalim

This problem still exisits on Devise 1.1.3

tekknikk avatar Oct 03 '10 23:10 tekknikk

Have this in Devise 1.1.5. I'm using the mongoid adapter so maybe that's where the problem is.

dbackeus avatar Jan 31 '11 09:01 dbackeus

Still existing in Devise 1.1.5. Using it without any adapters.

####I'm using the following fix from http://goo.gl/33TVf in my app/models/user.rb: before_validation :lowercase_email def lowercase_email self.email = self.email.downcase end def self.find_for_authentication(conditions) conditions[:email].downcase! if conditions[:email] super(conditions) end

alexschomb avatar Feb 13 '11 04:02 alexschomb

Thanks for the find_for_authentication fix.

An alternative to using callbacks for the email is to just override the email setter.

def email=(email)
  write_attribute(:email, email.try(:downcase))
end

dbackeus avatar Feb 14 '11 10:02 dbackeus

I just copied it from the quoted Google Group thread. Thanks for your solution, I find it to be even more straightforward.

alexschomb avatar Feb 15 '11 23:02 alexschomb

Why is this closed? This issue still exists in devise-1.4.2.

shawndrost avatar Aug 12 '11 21:08 shawndrost

You can configure it using case_insensitive_keys in your config/initializers/devise.rb. If it is not there, update your config file with rails g devise:install.

josevalim avatar Aug 12 '11 22:08 josevalim