Sha256: a9d7c093ef2656c4b24733d06e9a8df5b0026507d6e7c94fb4f68997deb1a992

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

require "digest/sha1"

module Authlogic
  module CryptoProviders
    # This class was made for the users transitioning from restful_authentication. I
    # highly discourage using this crypto provider as it is far inferior to your other
    # options. Please use any other provider offered by Authlogic.
    class Sha1
      class << self
        def join_token
          @join_token ||= "--"
        end
        attr_writer :join_token

        # The number of times to loop through the encryption. This is ten because that is
        # what restful_authentication defaults to.
        def stretches
          @stretches ||= 10
        end
        attr_writer :stretches

        # Turns your raw password into a Sha1 hash.
        def encrypt(*tokens)
          tokens = tokens.flatten
          digest = tokens.shift
          stretches.times do
            digest = Digest::SHA1.hexdigest([digest, *tokens].join(join_token))
          end
          digest
        end

        # Does the crypted password match the tokens? Uses the same tokens that were used
        # to encrypt.
        def matches?(crypted, *tokens)
          encrypt(*tokens) == crypted
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
authlogic-4.1.1 lib/authlogic/crypto_providers/sha1.rb
authlogic-4.1.0 lib/authlogic/crypto_providers/sha1.rb
authlogic-4.0.1 lib/authlogic/crypto_providers/sha1.rb
authlogic-4.0.0 lib/authlogic/crypto_providers/sha1.rb