Class: Authlogic::CryptoProviders::Sha1::V2
- Inherits:
-
Object
- Object
- Authlogic::CryptoProviders::Sha1::V2
- Defined in:
- lib/authlogic/crypto_providers/sha1/v2.rb
Overview
A poor choice. There are known attacks against this algorithm.
Class Attribute Summary collapse
- .join_token ⇒ Object
-
.stretches ⇒ Object
The number of times to loop through the encryption.
Class Method Summary collapse
-
.encrypt(*tokens) ⇒ Object
Turns your raw password into a Sha1 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
11 12 13 |
# File 'lib/authlogic/crypto_providers/sha1/v2.rb', line 11 def join_token @join_token ||= "--" end |
.stretches ⇒ Object
The number of times to loop through the encryption.
17 18 19 |
# File 'lib/authlogic/crypto_providers/sha1/v2.rb', line 17 def stretches @stretches ||= 10 end |
Class Method Details
.encrypt(*tokens) ⇒ Object
Turns your raw password into a Sha1 hash.
23 24 25 26 27 28 29 30 |
# File 'lib/authlogic/crypto_providers/sha1/v2.rb', line 23 def encrypt(*tokens) tokens = tokens.flatten digest = tokens.shift stretches.times do digest = Digest::SHA1.digest([digest, *tokens].join(join_token)) end digest.unpack1("H*") end |
.matches?(crypted, *tokens) ⇒ Boolean
Does the crypted password match the tokens? Uses the same tokens that were used to encrypt.
34 35 36 |
# File 'lib/authlogic/crypto_providers/sha1/v2.rb', line 34 def matches?(crypted, *tokens) encrypt(*tokens) == crypted end |