From 672852baafdd7cd9d47f19d1b9a3ed28129d4140 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Thu, 24 Jun 2010 03:08:20 +0000 Subject: [PATCH] Force string comparison for login search to be case sensitive on MySQL. #2473 Contributed by Holger Just. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3813 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/user.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index bbb3ff2ec..8148ae3a9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -225,10 +225,13 @@ class User < Principal # Find a user account by matching the exact login and then a case-insensitive # version. Exact matches will be given priority. def self.find_by_login(login) + # force string comparison to be case sensitive on MySQL + type_cast = (ActiveRecord::Base.connection.adapter_name == 'MySQL') ? 'BINARY' : '' + # First look for an exact match - user = first(:conditions => {:login => login}) + user = first(:conditions => ["#{type_cast} login = ?", login]) # Fail over to case-insensitive if none was found - user ||= first(:conditions => ["LOWER(login) = ?", login.to_s.downcase]) + user ||= first(:conditions => ["#{type_cast} LOWER(login) = ?", login.to_s.downcase]) end def self.find_by_rss_key(key)