Module: Platform::RandomPasswordGenerator

Defined in:
lib/platform/random_password_generator.rb

Constant Summary collapse

VOWELS =
['a', 'e', 'i', 'u']
CONSONANTS =
['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z']
DIGITS =
['2', '3', '4', '5', '6', '7', '8', '9']

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.a_part(slen) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# 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) ⇒ Object

def a_part



49
50
51
52
53
54
55
56
# 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) ⇒ Object

def n_part



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# 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

Instance Method Details

#random_password(alpha = 6, numeric = 2) ⇒ Object



31
32
33
# File 'lib/platform/random_password_generator.rb', line 31

def random_password(alpha=6, numeric=2)
  RandomPasswordGenerator.random_password(alpha, numeric)
end