Class: Authlogic::CryptoProviders::Sha1

Inherits:
Object
  • Object
show all
Defined in:
lib/authlogic/crypto_providers/sha1.rb

Overview

A poor choice. There are known attacks against this algorithm.

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.join_tokenObject



10
11
12
# File 'lib/authlogic/crypto_providers/sha1.rb', line 10

def join_token
  @join_token ||= "--"
end

.stretchesObject

The number of times to loop through the encryption.



16
17
18
# File 'lib/authlogic/crypto_providers/sha1.rb', line 16

def stretches
  @stretches ||= 10
end

Class Method Details

.encrypt(*tokens) ⇒ Object

Turns your raw password into a Sha1 hash.



22
23
24
25
26
27
28
29
# File 'lib/authlogic/crypto_providers/sha1.rb', line 22

def encrypt(*tokens)
  tokens = tokens.flatten
  digest = tokens.shift
  stretches.times do
    digest = Digest::SHA1.hexdigest([digest, *tokens].join(join_token))
  end
  digest
end

.matches?(crypted, *tokens) ⇒ Boolean

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

Returns:

  • (Boolean)


33
34
35
# File 'lib/authlogic/crypto_providers/sha1.rb', line 33

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