Sha256: 8673dd0d31bf7f50509578598b6e0113d8a953c20d65d89626062441fb5d5976

Contents?: true

Size: 1.07 KB

Versions: 9

Compression:

Stored size: 1.07 KB

Contents

require "digest/md5"
 
module Sorcery
  module CryptoProviders
    # This class was made for the users transitioning from md5 based systems. 
    # I highly discourage using this crypto provider as it superbly inferior 
    # to your other options.
    #
    # Please use any other provider offered by Sorcery.
    class MD5
      class << self
        attr_accessor :join_token
        
        # The number of times to loop through the encryption.
        def stretches
          @stretches ||= 1
        end
        attr_writer :stretches
        
        # Turns your raw password into a MD5 hash.
        def encrypt(*tokens)
          digest = tokens.flatten.join(join_token)
          stretches.times { digest = Digest::MD5.hexdigest(digest) }
          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 = 1
          @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/md5.rb
sorcery-0.3.0 lib/sorcery/crypto_providers/md5.rb
sorcery-0.2.1 lib/sorcery/crypto_providers/md5.rb
sorcery-0.2.0 lib/sorcery/crypto_providers/md5.rb
sorcery-0.1.4 lib/sorcery/crypto_providers/md5.rb
sorcery-0.1.3 lib/sorcery/crypto_providers/md5.rb
sorcery-0.1.2 lib/sorcery/crypto_providers/md5.rb
sorcery-0.1.1 lib/sorcery/crypto_providers/md5.rb
sorcery-0.1.0 lib/sorcery/crypto_providers/md5.rb