Sha256: 34cbc467674c297b8ff474031c0ba81324825485face2d046a7814425c5b45c8

Contents?: true

Size: 1.12 KB

Versions: 15

Compression:

Stored size: 1.12 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

15 entries across 15 versions & 2 rubygems

Version Path
godfat-rubycas-server-0.8.0.20090918 lib/casserver/authenticators/authlogic_crypto_providers/sha1.rb
refinerycms-0.9.6.34 vendor/plugins/authlogic/lib/authlogic/crypto_providers/sha1.rb
refinerycms-0.9.6.33 vendor/plugins/authlogic/lib/authlogic/crypto_providers/sha1.rb
refinerycms-0.9.6.32 vendor/plugins/authlogic/lib/authlogic/crypto_providers/sha1.rb
refinerycms-0.9.6.31 vendor/plugins/authlogic/lib/authlogic/crypto_providers/sha1.rb
refinerycms-0.9.6.30 vendor/plugins/authlogic/lib/authlogic/crypto_providers/sha1.rb
refinerycms-0.9.6.29 vendor/plugins/authlogic/lib/authlogic/crypto_providers/sha1.rb
refinerycms-0.9.6.28 vendor/plugins/authlogic/lib/authlogic/crypto_providers/sha1.rb
refinerycms-0.9.6.27 vendor/plugins/authlogic/lib/authlogic/crypto_providers/sha1.rb
refinerycms-0.9.6.26 vendor/plugins/authlogic/lib/authlogic/crypto_providers/sha1.rb
refinerycms-0.9.6.25 vendor/plugins/authlogic/lib/authlogic/crypto_providers/sha1.rb
refinerycms-0.9.6.24 vendor/plugins/authlogic/lib/authlogic/crypto_providers/sha1.rb
refinerycms-0.9.6.23 vendor/plugins/authlogic/lib/authlogic/crypto_providers/sha1.rb
refinerycms-0.9.6.22 vendor/plugins/authlogic/lib/authlogic/crypto_providers/sha1.rb
refinerycms-0.9.6.21 vendor/plugins/authlogic/lib/authlogic/crypto_providers/sha1.rb