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

Hosting

Website Checklist before Launching

Top 20 things to consider before launching your website

Tech

Getting wireless printing working on Virgin Media Hub 3

A guide on how to get wireless printing working on Virgin Media if yours has suddenly stopped working.