Module: Tolaria::RandomTokens

Defined in:
lib/tolaria/random_tokens.rb

Class Method Summary collapse

Class Method Details

.auth_tokenObject

Returns a 32-character random, alphanumeric string suitable for stronger token use like with cookies and API keys.



6
7
8
# File 'lib/tolaria/random_tokens.rb', line 6

def self.auth_token
  SecureRandom.base64(32).delete("+/=")[0..31]
end

.passcodeObject

Returns a six-digit numeric code suitable for use as a one-time passphrase. Leading zeroes are possible, encompassing 000000-999999.



12
13
14
# File 'lib/tolaria/random_tokens.rb', line 12

def self.passcode
  "%06d" % SecureRandom.random_number(1_000_000)
end