title: I need to authenticate a user directly in the console under Devise. How can I do it?
body: <p>I need to do something like this from Rails console to do some testing and experiments:</p>
  
  <blockquote>
    <p>User.authenticate(username, password)</p>
  </blockquote>
  
  <p>I'm using Devise, but I have no idea how to do this.</p>
  
  <p>I saw this other answer here</p>
  
  <p><a href="https://stackoverflow.com/questions/4929078/how-to-sign-in-a-user-using-devise-from-a-rails-console">How to sign in a user using Devise from a Rails console?</a></p>
  
  <p>But I need something cleaner and more direct. If necessary, I just need the algorithm to hash an attempted password with the salt and compare it to the encryped_password. </p>
  
  <p>Is it this?</p>
  
  <pre><code>User.find(1).valid_password?('password123') 
  </code></pre>