module Platform::RandomPasswordGenerator

Constants

CONSONANTS
DIGITS
VOWELS

Public Class Methods

a_part(slen) click to toggle source
# File lib/platform/random_password_generator.rb, line 35
def self.a_part(slen)
  ret = ''
  for i in 0...slen
    if i % 2 == 0
      randid = rand(CONSONANTS.length)
      ret = ret + CONSONANTS[randid]
    else
      randid = rand(VOWELS.length)
      ret = ret + VOWELS[randid]
    end
  end # for
  return ret
end
n_part(slen) click to toggle source
# File lib/platform/random_password_generator.rb, line 49
def self.n_part(slen)
  ret = ''
  for i in 0...slen
    randid = rand(DIGITS.length)
    ret = ret + DIGITS[randid]
  end # for
  return ret
end
random_password(alpha=6, numeric=2) click to toggle source
# File lib/platform/random_password_generator.rb, line 58
def self.random_password(alpha=6, numeric=2)

  fpl = alpha / 2
  if alpha % 2 != 0
    fpl = int(alpha / 2) + 1
  end
  lpl = alpha - fpl

  start = a_part(fpl)
  mid = n_part(numeric)
  tail = a_part(lpl)

  result = "%s%s%s" % [start, mid, tail]
  return result

end

Public Instance Methods

random_password(alpha=6, numeric=2) click to toggle source
# File lib/platform/random_password_generator.rb, line 31
def random_password(alpha=6, numeric=2)
  RandomPasswordGenerator.random_password(alpha, numeric)
end