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

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

- (Object) friendly_token



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

def friendly_token
  newpass = ""
  1.upto(20) { |i| newpass << FRIENDLY_CHARS[rand(FRIENDLY_CHARS.size-1)] }
  newpass
end

- (Object) hex_token



10
11
12
# File 'lib/authlogic/random.rb', line 10

def hex_token
  Authlogic::CryptoProviders::Sha512.encrypt(Time.now.to_s + (1..10).collect{ rand.to_s }.join)
end