module Sorcery::CryptoProviders::Common

Attributes

join_token[RW]
stretches[W]

Public Class Methods

encrypt(*tokens) click to toggle source
# File lib/sorcery/crypto_providers/common.rb, line 15
def encrypt(*tokens)
  digest = tokens.flatten.compact.join(join_token)
  stretches.times { digest = secure_digest(digest) }
  digest
end
included(base) click to toggle source
# File lib/sorcery/crypto_providers/common.rb, line 4
def self.included(base)
  base.class_eval do
    class << self
      attr_accessor :join_token

      # The number of times to loop through the encryption.
      def stretches
        @stretches ||= 1
      end
      attr_writer :stretches

      def encrypt(*tokens)
        digest = tokens.flatten.compact.join(join_token)
        stretches.times { digest = secure_digest(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.compact) == crypted
      end

      def reset!
        @stretches = 1
        @join_token = nil
      end
    end
  end
end
matches?(crypted, *tokens) click to toggle source

Does the crypted password match the tokens? Uses the same tokens that were used to encrypt.

# File lib/sorcery/crypto_providers/common.rb, line 22
def matches?(crypted, *tokens)
  encrypt(*tokens.compact) == crypted
end
reset!() click to toggle source
# File lib/sorcery/crypto_providers/common.rb, line 26
def reset!
  @stretches = 1
  @join_token = nil
end
stretches() click to toggle source

The number of times to loop through the encryption.

# File lib/sorcery/crypto_providers/common.rb, line 10
def stretches
  @stretches ||= 1
end