Module: Authlogic::Random

Extended by:
Random
Included in:
Random
Defined in:
lib/authlogic/random.rb

Overview

Handles generating random strings. If SecureRandom is installed it will default to this and use it instead. SecureRandom comes with ActiveSupport. So if you are using this in a rails app you should have this library.

Constant Summary collapse

SecureRandom =
(::SecureRandom) && ::SecureRandom) ||
(defined?(::ActiveSupport::SecureRandom) && ::ActiveSupport::SecureRandom)
FRIENDLY_CHARS =
("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a

Instance Method Summary collapse

Instance Method Details

#friendly_tokenObject



16
17
18
19
# File 'lib/authlogic/random.rb', line 16

def friendly_token
  # use base64url as defined by RFC4648
  SecureRandom.base64(15).tr('+/=', '').strip.delete("\n")
end

#hex_tokenObject



12
13
14
# File 'lib/authlogic/random.rb', line 12

def hex_token
  SecureRandom.hex(64)
end