ruby-on-rails - 我可以将 devise encrypted_pa​​ssword 与自定义身份验证一起使用吗?

标签 ruby-on-rails authentication devise

我有一个带有设计身份验证的 Rails 4 应用程序。我正在从头开始重建,想编写自己的身份验证系统,但我将用户存储在数据库中,其密码存储为 encrypted_pa​​ssword,这是设计用来存储散列密码的。我知道使用 bcrypt 我应该有一个 password_digest 列。

我的问题是双重的:bcrypt 是否能够读取我存储在我的设计 encrypted_pa​​ssword 列中的内容,如果是这样,我可以简单地将数据库列重命名为 password_digest或者这会导致问题吗?

最佳答案

根据我的阅读,是的,您应该能够重命名该列并将其与您的自定义身份验证一起使用。

引用资料: https://github.com/plataformatec/devise/blob/master/lib/devise/models/database_authenticatable.rb#L149-L151

module Devise
  def self.bcrypt(klass, password)
    ActiveSupport::Deprecation.warn "Devise.bcrypt is deprecated; use Devise::Encryptor.digest instead"
    Devise::Encryptor.digest(klass, password)
  end

  module Models
    module DatabaseAuthenticatable

      # Digests the password using bcrypt. Custom encryption should override
      # this method to apply their own algorithm.
      #
      # See https://github.com/plataformatec/devise-encryptable for examples
      # of other encryption engines.
      def password_digest(password)
        Devise::Encryptor.digest(self.class, password)
      end

和:

https://github.com/plataformatec/devise/blob/master/lib/devise/encryptor.rb#L5-L10

module Devise
  module Encryptor
    def self.digest(klass, password)
      if klass.pepper.present?
        password = "#{password}#{klass.pepper}"
      end
      ::BCrypt::Password.create(password, cost: klass.stretches).to_s
    end

关于ruby-on-rails - 我可以将 devise encrypted_pa​​ssword 与自定义身份验证一起使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32420068/

相关文章:

mysql - OSX dyld : lazy symbol binding failed: Symbol not found: _mysql_get_client_info

ruby-on-rails - 不断获取Authentication+failed.+API+credentials+are+incorrect

authentication - 如何使用 Post 方法获取 OAuth2 访问 token

ruby-on-rails - 我如何在邮件程序之外使用 Devise 的 `confirmation_url`?

ruby-on-rails - 如何修复 "uninitialized constant User"

ruby-on-rails - rails : Find relations on relations

css - 将字体添加到 rails

ASP.NET/MySQL : Access denied for user '' @'localhost' (using password: NO)

scala - Playframework 2.0 中用于身份验证和授权的 LDAP

ruby-on-rails-3 - 如何在 HAML 中为设计生成 View