Using Devise to verify an email address and password

How to go about using Devise to do verification on user credentials

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

Ruby

A quick tip to speed up bundle installs

Use more computing power to install gems faster

Rails

Getting Turbolinks to work with Webpack

How to re-add Turbolinks back into a Rails app when moving to Webpack