Sha256: 5c126b4682b24af6316cc345ff47caa57fd766bcbb6b30de24f9a45e689398b4

Contents?: true

Size: 1.14 KB

Versions: 67

Compression:

Stored size: 1.14 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 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 { digest = Digest::SHA1.hexdigest([digest, *tokens].join(join_token)) }
          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

67 entries across 67 versions & 25 rubygems

Version Path
authlogic-2.1.11 lib/authlogic/crypto_providers/sha1.rb
authlogic-2.1.10 lib/authlogic/crypto_providers/sha1.rb
arpitjain11-rubycas-server-0.8.0.20090613 lib/casserver/authenticators/authlogic_crypto_providers/sha1.rb
binarylogic-authlogic-2.1.0 lib/authlogic/crypto_providers/sha1.rb
binarylogic-authlogic-2.1.1 lib/authlogic/crypto_providers/sha1.rb
crankharder-authlogic-2.1.1 lib/authlogic/crypto_providers/sha1.rb
gunark-rubycas-server-0.8.0.20090812 lib/casserver/authenticators/authlogic_crypto_providers/sha1.rb
jlecour-authlogic-2.1.2 lib/authlogic/crypto_providers/sha1.rb
kschrader-authlogic-2.1.2 lib/authlogic/crypto_providers/sha1.rb
kschrader-authlogic-2.1.3 lib/authlogic/crypto_providers/sha1.rb
authlogic-3.1.3 lib/authlogic/crypto_providers/sha1.rb
authlogic-2.1.8 lib/authlogic/crypto_providers/sha1.rb
authlogic-2.1.7 lib/authlogic/crypto_providers/sha1.rb
authlogic-3.1.2 lib/authlogic/crypto_providers/sha1.rb
authlogic-3.1.1 lib/authlogic/crypto_providers/sha1.rb
nulogy-authlogic-3.1.0.1 lib/authlogic/crypto_providers/sha1.rb
Empact-authlogic-3.1.0 lib/authlogic/crypto_providers/sha1.rb
authlogic-3.1.0 lib/authlogic/crypto_providers/sha1.rb
Empact-authlogic-3.0.3 lib/authlogic/crypto_providers/sha1.rb
expertiza-authlogic-2.1.6.1 lib/authlogic/crypto_providers/sha1.rb