如何使用Devise和Rails 3验证用户名和密码是否正确 [英] How can I simply verify that a username and password are correct with Devise and Rails 3

查看:272
本文介绍了如何使用Devise和Rails 3验证用户名和密码是否正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Devise Rails 3

我想调用一个功能,只需验证用户的用户名和密码组合是否正确,而不实际登录该用户。有没有办法可以用Devise来完成这样的事情:

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])


推荐答案

让用户离开数据库:

user = User.find_by_email(params[:email])

然后,您可以通过以下方式检查他们的密码:

Then you can check their password with:

user.valid_password?(params[:password])

这篇关于如何使用Devise和Rails 3验证用户名和密码是否正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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