module GoodData::Helpers::CryptoHelper

Public Class Methods

generate_password() click to toggle source
# File lib/gooddata/helpers/crypto_helper.rb, line 13
def generate_password
  sprinkle(SecureRandom.base64(32))
end

Private Class Methods

digit() click to toggle source
# File lib/gooddata/helpers/crypto_helper.rb, line 33
def digit
  (0..9).to_a.sample.to_s
end
lower() click to toggle source
# File lib/gooddata/helpers/crypto_helper.rb, line 37
def lower
  ('a'..'z').to_a.sample
end
sprinkle(password) click to toggle source

Pseudo-randomly “sprinkles” the given string with 4 character groups (digit, lower case, upper case, symbols). @param [String] password

# File lib/gooddata/helpers/crypto_helper.rb, line 23
def sprinkle(password)
  password_dup = password.dup
  positions = 0..password.size
  password_dup.insert(rand(positions), digit)
  password_dup.insert(rand(positions), lower)
  password_dup.insert(rand(positions), upper)
  password_dup.insert(rand(positions), symbol)
  password_dup
end
symbol() click to toggle source
# File lib/gooddata/helpers/crypto_helper.rb, line 45
def symbol
  '!@#$%&/()+?*'.chars.sample
end
upper() click to toggle source
# File lib/gooddata/helpers/crypto_helper.rb, line 41
def upper
  ('A'..'Z').to_a.sample
end