我有一个带有设计身份验证的 Rails 4 应用程序。我正在从头开始重建,想编写自己的身份验证系统,但我将用户存储在数据库中,其密码存储为 encrypted_password
,这是设计用来存储散列密码的。我知道使用 bcrypt
我应该有一个 password_digest
列。
我的问题是双重的:bcrypt 是否能够读取我存储在我的设计 encrypted_password
列中的内容,如果是这样,我可以简单地将数据库列重命名为 password_digest
或者这会导致问题吗?
最佳答案
根据我的阅读,是的,您应该能够重命名该列并将其与您的自定义身份验证一起使用。
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_password 与自定义身份验证一起使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32420068/