繁体   English   中英

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

[英]Can I use devise encrypted_password with custom authentication?

我有一个带有设计认证的rails 4应用程序。 我正在从头开始重建并希望编写自己的身份验证系统,但我将用户存储在数据库中,其密码存储为encrypted_password ,这是设备用于存储哈希密码的用途。 我知道使用bcrypt我应该有一个password_digest列。

我的问题是双重的:bcrypt是否能够读取我在devise encrypted_password列中存储的内容,如果是这样,我可以简单地将该数据库列重命名为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 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM