Class: Authlogic::CryptoProviders::Sha512

Inherits:
Object
  • Object
show all
Defined in:
lib/authlogic/crypto_providers/sha512.rb

Overview

Sha512

Uses the Sha512 hash algorithm to encrypt passwords.

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.join_tokenObject

Returns the value of attribute join_token.



31
32
33
# File 'lib/authlogic/crypto_providers/sha512.rb', line 31

def join_token
  @join_token
end

.stretchesObject

The number of times to loop through the encryption. This is twenty because that is what restful_authentication defaults to.



35
36
37
# File 'lib/authlogic/crypto_providers/sha512.rb', line 35

def stretches
  @stretches ||= 20
end

Class Method Details

.encrypt(*tokens) ⇒ Object

Turns your raw password into a Sha512 hash.



41
42
43
44
45
# File 'lib/authlogic/crypto_providers/sha512.rb', line 41

def encrypt(*tokens)
  digest = tokens.flatten.join(join_token)
  stretches.times { digest = Digest::SHA512.hexdigest(digest) }
  digest
end

.matches?(crypted, *tokens) ⇒ Boolean

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

Returns:

  • (Boolean)


49
50
51
# File 'lib/authlogic/crypto_providers/sha512.rb', line 49

def matches?(crypted, *tokens)
  encrypt(*tokens) == crypted
end