I’ve got a strange problem with my user model in Rails 3.0.5.
When a user registers, case is view by the model: “Nicolas” is different from “nicolas”.
When a user login, case is not view by the model: “Nicolas” and “nicolas” are the same.
In my model:
validates_uniqueness_of :username
def self.authenticate(username, password)
user = find_by_username(username)
return user if user && user.status == 1 && user.password_hash == BCrypt::Engine.hash_secret(password, user.password_salt)
return nil
end
So “find_by_usename” will return the first user found for “Nicolas” or “nicolas”…
Any idea ?
By default, in MySQL, where are case insensitive.
So, if you want to do a case sensitive search, try something like this :
In your case, this will be :