Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7920369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:11:37+00:00 2026-06-03T16:11:37+00:00

In the same way most websites work, I was to store UsErNaMe in the

  • 0

In the same way most websites work, I was to store “UsErNaMe” in the database but let users login with “username”.

This is a fairly obvious and necessary feature, and plenty of people seem to have asked it, but the solution I keep stumbling upon seems disconnected from Devise’s own documentation.

For instance, consider this blog post: http://anti-pattern.com/2011/5/16/case-insensitive-keys-with-devise

[…]you’ve probably run into the problem that some users like to type
certain letters in their logins (email and/or username) in uppercase,
but expect it to be case-insensitive when they try to sign in. A not
unreasonable request[…]

Cool! That’s what I want.

His solution:

# config/initializers/devise.rb
Devise.setup do |config|
  config.case_insensitive_keys = [:email, :username]
end

That’s the solution I keep finding. But here’s the documentation for that config option:

# Configure which authentication keys should be case-insensitive.
# These keys will be downcased upon creating or modifying a user and when used
# to authenticate or find a user. Default is :email.
config.case_insensitive_keys = [ :username, :email ]

In particular: “These keys will be downcased upon creating/modifying a user.” In other words, the username is being downcased in the database.

To verify:

User.create username: "UsErNaMe", password: "secret", email: "email@com.com"
#=> <User username="username"...>

Am I missing something painfully obvious?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T16:11:41+00:00Added an answer on June 3, 2026 at 4:11 pm

    From devise wiki: you need to overwrite devise’s find_first_by_auth_conditions method in your model.

    ActiveRecord example:

    def self.find_first_by_auth_conditions(warden_conditions)
      conditions = warden_conditions.dup
      if login = conditions.delete(:login)
        where(conditions).where(["lower(username) = :value OR lower(email) = :value", { :value => login.downcase }]).first
      else
        where(conditions).first
      end
    end
    

    You can remove OR lower(email) = :value part if you don’t need auth by email too.

    That way you don’t need to list username in case_insensitive_keys and it wouldn’t be downcased in the database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not sure if Exceptions work the same way in each language, but
Given multiple websites all running the same sourcecode, what's the best/most maintainable way to
I'm looking for the most elegant way to count the same number values in
The same way i use this to detect when user scolled down the whole
I am trying to center these buttons, but most stuff online does not work.
Not sure if there's a better way to do this but I have a
I'm looking for the most efficient way to remove users with duplicate emails in
So in the same way that you could do @items.active.first to get the first
I want to use regular expression same way as string.Format. I will explain I
I'm trying to make it same way I made it for boost : find_package(Boost

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.