I am using Devise
and Rails 3
.
I want to call a function that will simply verify that a user's username
and password combination is correct without actually logging in that user. Is there some way I can accomplish something like this with Devise:
User.authenticate(params[:username], params[:password])
Devise is the cornerstone gem for Ruby on Rails authentication. With Devise, creating a User that can log in and out of your application is so simple because Devise takes care of all the controllers necessary for user creation ( users_controller ) and for user sessions ( users_sessions_controller ).
Get the user out of the database:
user = User.find_by_email(params[:email])
Then you can check their password with:
user.valid_password?(params[:password])
Or using the one liner:
User.find_by_email(params[:email]).try(:valid_password?, params[:password])
which returns true
or nil
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With