Class: Authlogic::CryptoProviders::Sha1
- Inherits:
-
Object
- Object
- Authlogic::CryptoProviders::Sha1
- Defined in:
- lib/casserver/authenticators/authlogic_crypto_providers/sha1.rb
Overview
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 any other provider offered by Authlogic.
Class Attribute Summary collapse
- .join_token ⇒ Object
-
.stretches ⇒ Object
The number of times to loop through the encryption.
Class Method Summary collapse
-
.digest(tokens) ⇒ Object
This is for “old style” authentication with a custom format of digest.
- .digest_format=(format) ⇒ Object
-
.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
10 11 12 |
# File 'lib/casserver/authenticators/authlogic_crypto_providers/sha1.rb', line 10 def join_token @join_token ||= "--" end |
.stretches ⇒ Object
The number of times to loop through the encryption. This is ten because that is what restful_authentication defaults to.
33 34 35 |
# File 'lib/casserver/authenticators/authlogic_crypto_providers/sha1.rb', line 33 def stretches @stretches ||= 10 end |
Class Method Details
.digest(tokens) ⇒ Object
This is for “old style” authentication with a custom format of digest
20 21 22 23 24 25 26 27 28 |
# File 'lib/casserver/authenticators/authlogic_crypto_providers/sha1.rb', line 20 def digest(tokens) if @digest_format @digest_format. gsub('PASSWORD', tokens.first). gsub('SALT', tokens.last) else tokens.join(join_token) end end |
.digest_format=(format) ⇒ Object
15 16 17 |
# File 'lib/casserver/authenticators/authlogic_crypto_providers/sha1.rb', line 15 def digest_format=(format) @digest_format = format end |
.encrypt(*tokens) ⇒ Object
Turns your raw password into a Sha1 hash.
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/casserver/authenticators/authlogic_crypto_providers/sha1.rb', line 39 def encrypt(*tokens) tokens = tokens.flatten if stretches > 1 hash = tokens.shift stretches.times { hash = Digest::SHA1.hexdigest([hash, *tokens].join(join_token)) } else hash = Digest::SHA1.hexdigest( digest(tokens) ) end hash end |
.matches?(crypted, *tokens) ⇒ Boolean
Does the crypted password match the tokens? Uses the same tokens that were used to encrypt.
53 54 55 |
# File 'lib/casserver/authenticators/authlogic_crypto_providers/sha1.rb', line 53 def matches?(crypted, *tokens) encrypt(*tokens) == crypted end |