Module: Authtools::Token

Extended by:
Common, Token
Included in:
Token
Defined in:
lib/authtools/token.rb

Constant Summary collapse

TINY =
128
SHORT =
256
MEDIUM =
384
LONG =
512

Instance Method Summary collapse

Methods included from Common

salt

Instance Method Details

#generate(size = SHORT) ⇒ Object

Generates new token with specified size.



17
18
19
20
21
22
23
24
25
26
# File 'lib/authtools/token.rb', line 17

def generate(size=SHORT)
  size = const_get(size.to_s.upcase) if [:tiny, :short, :medium, :long].include?(size)
  if size > 128
    hash = Digest::SHA2.new(size)
    hash << self.salt
  else
    hash = Digest::MD5.hexdigest(self.salt)
  end
  hash.to_s
end

#new(size = SHORT) ⇒ Object

Alias for generate method.



30
31
32
# File 'lib/authtools/token.rb', line 30

def new(size=SHORT)
  generate(size)
end