如何使用Devise和Rails 3验证用户名和密码是否正确

如何使用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])