How to verify a user's password in Devise

poporul picture poporul · Dec 1, 2010 · Viewed 55.4k times · Source

I'm having a problem matching user password using devise gem in rails. User password stored on my db which is encrypted_password and i am trying to find user by password, but I don't understand how to match password from form and encrypted_password in my db.

User.find_by_email_and_password(params[:user][:email], params[:user][:password])

Answer

joshaidan picture joshaidan · Dec 6, 2010

I think this is a better, and more elegant way of doing it:

user = User.find_by_email(params[:user][:email])
user.valid_password?(params[:user][:password])

The other method where you generate the digest from the user instance was giving me protected method errors.