【问题标题】:How to check that old password is equal to that one in database如何检查旧密码是否与数据库中的密码相同
【发布时间】:2016-01-06 15:19:46
【问题描述】:

我想在 Rails 中更改密码我想将旧密码作为字符串输入并与数据库中的加密密码进行检查我正在使用 Devise gem 我该怎么做

【问题讨论】:

标签: ruby-on-rails devise


【解决方案1】:

你想要 Devise 的 valid_password? 方法。

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

【讨论】:

    【解决方案2】:

    Devise 已经为您提供了此功能。它应该可以使用edit_user_registration_path 开箱即用。

    查看https://github.com/plataformatec/devise/wiki/How-To%3a-Allow-users-to-edit-their-password 了解更多信息。

    【讨论】:

      猜你喜欢
      • 2020-11-27
      • 2018-04-16
      • 1970-01-01
      • 1970-01-01
      • 2019-07-08
      • 2017-01-17
      • 2020-07-03
      • 1970-01-01
      • 2017-11-12
      相关资源
      最近更新 更多