Sha256: 079724c6fd5220b0f35e65eccec65ea114039b3cac44dc0c313812ee98bbc5f8

Contents?: true

Size: 1.81 KB

Versions: 48

Compression:

Stored size: 1.81 KB

Contents

require "digest/sha2"

module Authlogic
  # The acts_as_authentic method has a crypto_provider option. This allows you to use any type of encryption you like.
  # Just create a class with a class level encrypt and matches? method. See example below.
  #
  # === Example
  #
  #   class MyAwesomeEncryptionMethod
  #     def self.encrypt(*tokens)
  #       # the tokens passed will be an array of objects, what type of object is irrelevant,
  #       # just do what you need to do with them and return a single encrypted string.
  #       # for example, you will most likely join all of the objects into a single string and then encrypt that string
  #     end
  #
  #     def self.matches?(crypted, *tokens)
  #       # return true if the crypted string matches the tokens.
  #       # depending on your algorithm you might decrypt the string then compare it to the token, or you might
  #       # encrypt the tokens and make sure it matches the crypted string, its up to you
  #     end
  #   end
  module CryptoProviders
    # = Sha512
    #
    # Uses the Sha512 hash algorithm to encrypt passwords.
    class Sha512
      class << self
        attr_accessor :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 ||= 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

48 entries across 48 versions & 8 rubygems

Version Path
godfat-rubycas-server-0.8.0.20090918 lib/casserver/authenticators/authlogic_crypto_providers/sha512.rb
synapse-rubycas-server-1.1.6 lib/casserver/authenticators/authlogic_crypto_providers/sha512.rb
synapse-rubycas-server-1.1.5.pre lib/casserver/authenticators/authlogic_crypto_providers/sha512.rb
synapse-rubycas-server-1.1.4.pre lib/casserver/authenticators/authlogic_crypto_providers/sha512.rb
synapse-rubycas-server-1.1.4 lib/casserver/authenticators/authlogic_crypto_providers/sha512.rb
synapse-rubycas-server-1.1.3alpha lib/casserver/authenticators/authlogic_crypto_providers/sha512.rb
synapse-rubycas-server-1.1.3.pre lib/casserver/authenticators/authlogic_crypto_providers/sha512.rb
synapses-cas-0.1.11 lib/casserver/authenticators/authlogic_crypto_providers/sha512.rb
synapses-cas-0.1.10 lib/casserver/authenticators/authlogic_crypto_providers/sha512.rb
synapses-cas-0.1.9 lib/casserver/authenticators/authlogic_crypto_providers/sha512.rb
ror-rubycas-server-1.0.c lib/casserver/authenticators/authlogic_crypto_providers/sha512.rb
ror-rubycas-server-1.0.b lib/casserver/authenticators/authlogic_crypto_providers/sha512.rb
ror-rubycas-server-1.0.a lib/casserver/authenticators/authlogic_crypto_providers/sha512.rb
rubycas-server-1.1.2 lib/casserver/authenticators/authlogic_crypto_providers/sha512.rb
synapses-cas-0.1.8 lib/casserver/authenticators/authlogic_crypto_providers/sha512.rb
synapses-cas-0.1.7 lib/casserver/authenticators/authlogic_crypto_providers/sha512.rb
rubycas-server-1.1.1 lib/casserver/authenticators/authlogic_crypto_providers/sha512.rb
synapses-cas-0.1.6 lib/casserver/authenticators/authlogic_crypto_providers/sha512.rb
synapses-cas-0.1.5 lib/casserver/authenticators/authlogic_crypto_providers/sha512.rb
synapses-cas-0.1.4 lib/casserver/authenticators/authlogic_crypto_providers/sha512.rb