Class: Authentication::Logic::CryptoProviders::Sha256::V2
- Inherits:
-
Object
- Object
- Authentication::Logic::CryptoProviders::Sha256::V2
- Defined in:
- lib/auth/logic/crypto_providers/sha256/v2.rb
Overview
Sha256
Uses the Sha256 hash algorithm to encrypt passwords.
Class Attribute Summary collapse
-
.join_token ⇒ Object
Returns the value of attribute join_token.
-
.stretches ⇒ Object
The number of times to loop through the encryption.
Class Method Summary collapse
-
.encrypt(*tokens) ⇒ Object
Turns your raw password into a Sha256 hash.
-
.matches?(crypted, *tokens) ⇒ Boolean
Does the crypted password match the tokens? Uses the same tokens that were used to encrypt.
Class Attribute Details
.join_token ⇒ Object
Returns the value of attribute join_token.
35 36 37 |
# File 'lib/auth/logic/crypto_providers/sha256/v2.rb', line 35 def join_token @join_token end |
.stretches ⇒ Object
The number of times to loop through the encryption.
38 39 40 |
# File 'lib/auth/logic/crypto_providers/sha256/v2.rb', line 38 def stretches @stretches ||= 20 end |
Class Method Details
.encrypt(*tokens) ⇒ Object
Turns your raw password into a Sha256 hash.
44 45 46 47 48 |
# File 'lib/auth/logic/crypto_providers/sha256/v2.rb', line 44 def encrypt(*tokens) digest = tokens.flatten.join(join_token) stretches.times { digest = Digest::SHA256.digest(digest) } digest.unpack1("H*") end |
.matches?(crypted, *tokens) ⇒ Boolean
Does the crypted password match the tokens? Uses the same tokens that were used to encrypt.
52 53 54 |
# File 'lib/auth/logic/crypto_providers/sha256/v2.rb', line 52 def matches?(crypted, *tokens) encrypt(*tokens) == crypted end |