Answer the question
In order to leave comments, you need to log in
How to check the password from the database with the new password for a match in Rails?
There is a password from the form: params[:user][:password]
I want to check if the password from the database matches. The password in the database is stored in a hashed form (via bcrypt), and, accordingly, it is impossible to check the password in this way:
@user = User.where(password: params[:user][:password]).first
Answer the question
In order to leave comments, you need to log in
Solved the problem with simple usage:
password = params[:user][:password]
User.find_by(id:user_id).try(:authenticate, password)
Read this: https://github.com/codahale/bcrypt-ruby for how to use bcrypt in Rails
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question