Using Devise to verify an email address and password

Devise is a very powerful tool for handling authentication in Ruby applications, so powerful in fact that sometimes when I need to do simple tasks I found I get a little drowned in the weight of people talking about use cases far more complex than the one I want to fulfill.

One such example is verifying an email address and password. I don't need to log the user in or associate them with any role or anything, I just want to know if the submitted email/password combination is a valid one.

My mistake was I was searching for help by searching for things like "Check Sign In Details" or "Verify Log In Details", which were returning results relating to a method called sign_in, which is very useful but not what I needed here.

Here is the code you need to verify if an email address and password combo is valid, this obviously assumes that you have devise already set up and working correctly on your user model.

user = User.find_by_email(params[:email])
if user.valid_password?(params[:password])
  # Valid!
else
  # Not Valid!
end

Pretty straightforward!

Recent posts View all

Talk CSS

FrontEnders - Web Performance

Sharing some of my thoughts on a FrontEnders meetup on the topic of Web Performance

Conferences

Tips for how to ask for time off to attend conferences

Asking for time off to attend a conference can be nerve-racking, these tips will get you closer to attending the conferences you're interested in.