Class: Authlogic::CryptoProviders::Sha1

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

Overview

Sha1

This class was made for the users transitioning from restful_authentication. I highly discourage using this crypto provider as it inferior to your other options. Please use the Sha512 crypto provider or the BCrypt provider.

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.join_tokenObject



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

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

.stretchesObject

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



17
18
19
# File 'lib/authlogic/crypto_providers/sha1.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
# File 'lib/authlogic/crypto_providers/sha1.rb', line 23

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

.matches?(crypted, *tokens) ⇒ Boolean

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

Returns:

  • (Boolean)


31
32
33
# File 'lib/authlogic/crypto_providers/sha1.rb', line 31

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