Class: Zas::CryptoProviders::Sha512

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

Overview

Public: Uses the Sha512 hash algorithm to encrypt passwords.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#stretchesObject

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



8
9
10
# File 'lib/zas/crypto_providers/sha512.rb', line 8

def stretches
  @stretches ||= 20
end

Instance Method Details

#encrypt(*tokens) ⇒ Object

Public: Turns your raw password into a Sha512 hash.

tokens - The tokens to encrypt

Returns the encrypted string



18
19
20
21
22
# File 'lib/zas/crypto_providers/sha512.rb', line 18

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

#matches?(crypted, *tokens) ⇒ Boolean

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

crytped - The crypted value tokens - A collection of tokens to encrypt

Returns:

  • (Boolean)


28
29
30
# File 'lib/zas/crypto_providers/sha512.rb', line 28

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