그것은 아무도 내 질문에 대답 없다는 슬픈 ......
를 사용하고 그것은 내가 상상처럼 예쁜 아니다 있지만, 내가 답을 찾은 것 같아요.
첫째, 이니셜 암호화 클래스 생성 : 암호를 암호화 할 때 가르 칠
# overwrite this method so that we call the encryptor class properly
def encrypt_password
unless @password.blank?
self.password_salt = self.class.encryptor_class.salt(email)
self.encrypted_password = self.class.encryptor_class.digest(@password, self.password_salt)
end
end
# Because when the database_authenticatable wrote the following method to regenerate the password, which in turn passed incorrect params to the encrypt_password, these overwrite is needed!
def password=(password)
@password = password
end
def password_digest(pwd)
self.class.encryptor_class.digest(pwd, self.password_salt)
end
그리고 마지막으로, 우리가 가진 : 사용자 모델에서 몇 가지 방법을 덮어, 둘째
module Devise
module Encryptors
class MySha1 < Base
def self.digest(password, salt)
Digest::SHA1.hexdigest("#{salt}-----#{password}")
end
def self.salt(email)
Digest::SHA1.hexdigest("#{Time.now}-----#{email}")
end
end
end
end
을 :
before_save :encrypt_password
왜 표준 방법 대신 전자 메일과 사용자 지정 소금을 포함 하시겠습니까? – Peder
오래 전이었고, 기억이 잘된다면 암호를 변경하기 전에 암호화를 사용하여 이메일에서 다른 소금을 사용했습니다. 따라서 사용자에게 영향을 미치지 않으려면 암호화 된 암호화를 원래의 암호화와 동일한 결과를 얻을 수 있도록 미세 조정해야합니다. – PeterWong