誰も私の質問に答えてくれなかったのは悲しい......
しかし、想像したほどきれいではありませんが、答えを見つけたと思います。
まず、初期化子で暗号化クラスを作成します。
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
次に、User モデルのいくつかのメソッドを上書きします。
# 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
そして最後に、いつパスワードを暗号化するかを教えなければなりません:
before_save :encrypt_password