Class: Authlogic::CryptoProviders::Sha512

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

Overview

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.

Defined Under Namespace

Classes: V2

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.join_tokenObject

Returns the value of attribute join_token.



15
16
17
# File 'lib/authlogic/crypto_providers/sha512.rb', line 15

def join_token
  @join_token
end

.stretchesObject

The number of times to loop through the encryption.



18
19
20
# File 'lib/authlogic/crypto_providers/sha512.rb', line 18

def stretches
  @stretches ||= 20
end

Class Method Details

.encrypt(*tokens) ⇒ Object

Turns your raw password into a Sha512 hash.



24
25
26
27
28
# File 'lib/authlogic/crypto_providers/sha512.rb', line 24

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)


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

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