Class: Authlogic::CryptoProviders::Sha256

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

Overview

Sha256

Uses the Sha256 hash algorithm to encrypt passwords.

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.



36
37
38
# File 'lib/authlogic/crypto_providers/sha256.rb', line 36

def join_token
  @join_token
end

.stretchesObject

The number of times to loop through the encryption.



39
40
41
# File 'lib/authlogic/crypto_providers/sha256.rb', line 39

def stretches
  @stretches ||= 20
end

Class Method Details

.encrypt(*tokens) ⇒ Object

Turns your raw password into a Sha256 hash.



45
46
47
48
49
# File 'lib/authlogic/crypto_providers/sha256.rb', line 45

def encrypt(*tokens)
  digest = tokens.flatten.join(join_token)
  stretches.times { digest = Digest::SHA256.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)


53
54
55
# File 'lib/authlogic/crypto_providers/sha256.rb', line 53

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