Class: Authentication::Logic::CryptoProviders::MD5::V2

Inherits:
Object
  • Object
show all
Defined in:
lib/auth/logic/crypto_providers/md5/v2.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

Returns the value of attribute join_token.



12
13
14
# File 'lib/auth/logic/crypto_providers/md5/v2.rb', line 12

def join_token
  @join_token
end

.stretchesObject

The number of times to loop through the encryption.



15
16
17
# File 'lib/auth/logic/crypto_providers/md5/v2.rb', line 15

def stretches
  @stretches ||= 1
end

Class Method Details

.encrypt(*tokens) ⇒ Object

Turns your raw password into a MD5 hash.



21
22
23
24
25
# File 'lib/auth/logic/crypto_providers/md5/v2.rb', line 21

def encrypt(*tokens)
  digest = tokens.flatten.join(join_token)
  stretches.times { digest = Digest::MD5.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.

Returns:

  • (Boolean)


29
30
31
# File 'lib/auth/logic/crypto_providers/md5/v2.rb', line 29

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