Module: Authtools::Token
Constant Summary collapse
- TINY =
128
- SHORT =
256
- MEDIUM =
384
- LONG =
512
Instance Method Summary collapse
-
#generate(size = SHORT) ⇒ Object
Generates new token with specified size.
-
#new(size = SHORT) ⇒ Object
Alias for generate method.
Methods included from Common
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 |