title: How do I find user by username rather than email in ruby on rails 3.1?
body: <p>I've tried a few things but can't seem to get my head round it. I've been practicing and know how to do this using email but how can I do it using username?  </p>
  
  <pre><code>def self.authenticate(username, password)
      user = find_by_name(username)
      if user &amp;&amp; user.password_hash ==  BCrypt::Engine.hash_secret(password, user.password_salt)
      user
      else
        nil
      end
  end
  </code></pre>