2009-11-10 15:55:13 -05:00
|
|
|
require "digest/sha1"
|
2009-11-10 10:27:43 -05:00
|
|
|
|
|
|
|
module Devise
|
|
|
|
module Encryptors
|
|
|
|
# = Sha1
|
|
|
|
# Uses the Sha1 hash algorithm to encrypt passwords.
|
2010-01-08 17:19:57 -05:00
|
|
|
class Sha1 < Base
|
2011-11-09 17:46:28 -05:00
|
|
|
# Generates a default password digest based on stretches, salt, pepper and the
|
2009-11-10 10:27:43 -05:00
|
|
|
# incoming password.
|
|
|
|
def self.digest(password, stretches, salt, pepper)
|
|
|
|
digest = pepper
|
|
|
|
stretches.times { digest = self.secure_digest(salt, digest, password, pepper) }
|
|
|
|
digest
|
|
|
|
end
|
|
|
|
|
2010-06-12 08:46:55 -04:00
|
|
|
private
|
2009-11-10 10:27:43 -05:00
|
|
|
|
2010-06-12 08:46:55 -04:00
|
|
|
# Generate a SHA1 digest joining args. Generated token is something like
|
|
|
|
# --arg1--arg2--arg3--argN--
|
|
|
|
def self.secure_digest(*tokens)
|
|
|
|
::Digest::SHA1.hexdigest('--' << tokens.flatten.join('--') << '--')
|
|
|
|
end
|
2009-11-10 10:27:43 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|