mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
22 lines
812 B
Ruby
22 lines
812 B
Ruby
require "digest/sha1"
|
|
|
|
module Devise
|
|
module Encryptors
|
|
# = RestfulAuthenticationSha1
|
|
# Simulates Restful Authentication's default encryption mechanism.
|
|
# Warning: it uses Devise's pepper to port the concept of REST_AUTH_SITE_KEY
|
|
# Warning: it uses Devise's stretches configuration to port the concept of REST_AUTH_DIGEST_STRETCHES. Should be set to 10 in
|
|
# the initializer to simulate the default behavior.
|
|
class RestfulAuthenticationSha1 < Base
|
|
|
|
# Gererates a default password digest based on salt, pepper and the
|
|
# incoming password.
|
|
def self.digest(password, stretches, salt, pepper)
|
|
digest = pepper
|
|
stretches.times { digest = Digest::SHA1.hexdigest([digest, salt, password, pepper].flatten.join('--')) }
|
|
digest
|
|
end
|
|
|
|
end
|
|
end
|
|
end
|