如何在设计中验证用户的密码 [英] How to verify a user's password in Devise

查看:16
本文介绍了如何在设计中验证用户的密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Rails 中使用 devise gem 匹配用户密码时遇到问题.用户密码存储在我的数据库中,它是 encrypted_pa​​ssword,我试图通过密码查找用户,但我不明白如何在我的数据库中匹配来自表单的密码和 encrypted_pa​​ssword.

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.

这篇关于如何在设计中验证用户的密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆