本文介绍了如何在Devise中验证用户的密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在rails中使用devise gem匹配用户密码时遇到问题。存储在我的db上的用户密码是encrypted_password,我正在尝试通过密码找到用户,但我不明白如何在我的数据库中匹配表单和encrypted_password的密码。
User.find_by_email_and_password(params [:user] [:email],params [:user] [:password])
解决方案
我认为这是一个更好,更优雅的方式:
$ pre $
user = User.find_by_email(params [:user] [:email])
user.valid_password?(params [:user] [:password])
从用户实例生成摘要的其他方法是给我保护方法错误。
I'm having a problem matching user password using devise gem in rails. User password stored on my db which is encrypted_password and i am trying to find user by password, but I don't understand how to match password from form and encrypted_password in my db.
User.find_by_email_and_password(params[:user][:email], params[:user][:password])
解决方案
I think this is a better, and more elegant way of doing it:
user = User.find_by_email(params[:user][:email])
user.valid_password?(params[:user][:password])
The other method where you generate the digest from the user instance was giving me protected method errors.
这篇关于如何在Devise中验证用户的密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!