Rails Devise:身份验证时不检查密码盐

发布于 2024-11-18 01:43:32 字数 524 浏览 3 评论 0原文

我正在使用 Devise 作为身份验证方法将 PHP 站点迁移到 Rails。旧站点使用 md5(盐 + 密码)来验证用户身份,因此我编写了一个自定义 Devise 加密器,如下所示:

module Devise
  module Encryptors
    class Md5 < Base
      def self.digest(password, stretches, pepper)
        Digest::MD5.hexdigest(password + 'the_salt_value')
      end
    end
  end
end

当我使用密码“password”在新站点上创建新用户时,散列密码与旧站点上的用户相匹配密码为“password”,这很好。但是,password_salt 列中的值(我不清楚其用途)是不同的,当我迁移数据库时,旧站点上的用户无法使用“密码”登录。

处理这个问题的最佳方法是什么?有没有办法让 Devise 在身份验证时简单地比较 crypto_password 列中的值?

I'm migrating a PHP site over to Rails using Devise as the authentication method. The old site uses md5(salt + password) to authenticate users so I wrote a custom Devise encryptor as such:

module Devise
  module Encryptors
    class Md5 < Base
      def self.digest(password, stretches, pepper)
        Digest::MD5.hexdigest(password + 'the_salt_value')
      end
    end
  end
end

When I create a new user on the new site with the password "password", the hashed password matches the user on the old site with the password "password", which is good. However, the values in the password_salt column, whose purpose I'm unclear on, are different and the user on the old site can't login with "password" when I migrate the database over.

What's the best way to deal with this problem? Is there a way to make Devise simply compare the values in the encrypted_password column when authenticating?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文