找到你要的答案

Q:How to check that old password is equal to that one in database

Q:如何检查旧密码是否等于数据库中的密码

I want to make a change password in rails i want to enter the old password as a string and check it with the encrypted one in the database i am using Devise gem how can i do this

我想做一个更改密码在Rails我想输入旧密码作为一个字符串,并检查它与加密的一个在数据库中我使用设计宝石我怎么能做到这一点

answer1: 回答1:

Devise already provides you with this functionality. It should probably work out of the box using the edit_user_registration_path.

Have a look at https://github.com/plataformatec/devise/wiki/How-To%3a-Allow-users-to-edit-their-password to find some more information.

设计已经为您提供了这个功能。它应该工作开箱使用edit_user_registration_path。

在HTTPS一看:/ / GitHub。COM / plataformatec /设计/维基/如何为3a允许用户编辑自己的密码来找到更多的信息。

answer2: 回答2:

You want Devise's valid_password? method.

> user = User.find(1)
> user.valid_password?('invalidpassword')
=> false
> user.valid_password?('therealpassword')
=> true

你要设计的valid_password?方法。

> user = User.find(1)
> user.valid_password?('invalidpassword')
=> false
> user.valid_password?('therealpassword')
=> true
ruby-on-rails  devise