Sha256: 785d2a8629c90bb8b0ab40abd39cb65e12fecb062f550b4726cb857e57115d92

Contents?: true

Size: 1.05 KB

Versions: 20

Compression:

Stored size: 1.05 KB

Contents

require "digest/sha1"

module Devise
  # Implements a way of adding different encryptions.
  # The class should implement a self.digest method that taks the following params:
  #   - password
  #   - stretches: the number of times the encryption will be applied
  #   - salt: the password salt as defined by devise
  #   - pepper: Devise config option
  #
  module Encryptors
    # = Sha1
    # Uses the Sha1 hash algorithm to encrypt passwords.
    class Sha1
      
      # Gererates a default password digest based on stretches, salt, pepper and the
      # incoming password.
      def self.digest(password, stretches, salt, pepper)
        digest = pepper
        stretches.times { digest = self.secure_digest(salt, digest, password, pepper) }
        digest
      end

      private

        # 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        
      
    end
  end
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
devise-0.8.0 lib/devise/encryptors/sha1.rb
devise-0.7.5 lib/devise/encryptors/sha1.rb
devise-0.7.4 lib/devise/encryptors/sha1.rb
devise-0.7.3 lib/devise/encryptors/sha1.rb
devise-0.7.2 lib/devise/encryptors/sha1.rb
devise-0.7.1 lib/devise/encryptors/sha1.rb
devise-0.7.0 lib/devise/encryptors/sha1.rb
devise-0.6.3 lib/devise/encryptors/sha1.rb
devise-0.6.2 lib/devise/encryptors/sha1.rb
devise-0.6.1 lib/devise/encryptors/sha1.rb
devise-0.6.0 lib/devise/encryptors/sha1.rb
devise-0.5.6 lib/devise/encryptors/sha1.rb
devise-0.5.5 lib/devise/encryptors/sha1.rb
devise-0.5.4 lib/devise/encryptors/sha1.rb
devise-0.5.3 lib/devise/encryptors/sha1.rb
devise-0.5.2 lib/devise/encryptors/sha1.rb
devise-0.5.1 lib/devise/encryptors/sha1.rb
devise-0.5.0 lib/devise/encryptors/sha1.rb
shingara-devise-0.4.3.1 lib/devise/encryptors/sha1.rb
shingara-devise-0.4.3 lib/devise/encryptors/sha1.rb