2009-11-10 10:27:43 -05:00
|
|
|
require "digest/sha2"
|
|
|
|
|
|
|
|
module Devise
|
|
|
|
module Encryptors
|
|
|
|
# = AuthlogicSha512
|
|
|
|
# Simulates Authlogic's default encryption mechanism.
|
2010-12-23 02:25:10 -05:00
|
|
|
# Warning: it uses Devise's stretches configuration to port Authlogic's one. Should be set to 20 in the initializer to simulate
|
2009-11-10 10:27:43 -05:00
|
|
|
# the default behavior.
|
2010-01-08 17:19:57 -05:00
|
|
|
class AuthlogicSha512 < Base
|
2009-11-10 10:27:43 -05:00
|
|
|
# Gererates a default password digest based on salt, pepper and the
|
|
|
|
# incoming password.
|
|
|
|
def self.digest(password, stretches, salt, pepper)
|
|
|
|
digest = [password, salt].flatten.join('')
|
|
|
|
stretches.times { digest = Digest::SHA512.hexdigest(digest) }
|
|
|
|
digest
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|