Sha256: 0423dd08fcf541e598b78e88ee1c1891056bd45fa037708ee10365e4e108ee60

Contents?: true

Size: 990 Bytes

Versions: 7

Compression:

Stored size: 990 Bytes

Contents

# frozen_string_literal: true

require "digest/sha2"

module Authlogic
  module CryptoProviders
    # SHA-512 does not have any practical known attacks against it. However,
    # there are better choices. We recommend transitioning to a more secure,
    # adaptive hashing algorithm, like scrypt.
    class Sha512
      class << self
        attr_accessor :join_token

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

        # Turns your raw password into a Sha512 hash.
        def encrypt(*tokens)
          digest = tokens.flatten.join(join_token)
          stretches.times { digest = Digest::SHA512.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
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
authlogic-5.2.0 lib/authlogic/crypto_providers/sha512.rb
authlogic-5.1.0 lib/authlogic/crypto_providers/sha512.rb
authlogic-5.0.4 lib/authlogic/crypto_providers/sha512.rb
authlogic-5.0.3 lib/authlogic/crypto_providers/sha512.rb
authlogic-5.0.2 lib/authlogic/crypto_providers/sha512.rb
authlogic-5.0.1 lib/authlogic/crypto_providers/sha512.rb
authlogic-5.0.0 lib/authlogic/crypto_providers/sha512.rb