Sha256: 5bf26e5b3eaac990faa8e9399f9fa39cf76169e48fac457e33041d0a089750b0

Contents?: true

Size: 1.23 KB

Versions: 9

Compression:

Stored size: 1.23 KB

Contents

require "digest/sha1"

module Sorcery
  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 Sorcery.
    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
        
        def reset!
          @stretches = 10
          @join_token = nil
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
sorcery-0.3.1 lib/sorcery/crypto_providers/sha1.rb
sorcery-0.3.0 lib/sorcery/crypto_providers/sha1.rb
sorcery-0.2.1 lib/sorcery/crypto_providers/sha1.rb
sorcery-0.2.0 lib/sorcery/crypto_providers/sha1.rb
sorcery-0.1.4 lib/sorcery/crypto_providers/sha1.rb
sorcery-0.1.3 lib/sorcery/crypto_providers/sha1.rb
sorcery-0.1.2 lib/sorcery/crypto_providers/sha1.rb
sorcery-0.1.1 lib/sorcery/crypto_providers/sha1.rb
sorcery-0.1.0 lib/sorcery/crypto_providers/sha1.rb