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 to verify if an email address and password combo is valid, this 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

VS CodeWeb Dev

Select multiple lines in VS Code

How to select multiple lines to edit at once within VS Code

VS Code Web Dev

Move a line up or down with VS Code

A quick tip on moving lines up or down a file using your keyboard in VS Code