Module: RandomPassword

Defined in:
lib/random/password.rb,
lib/random/password/version.rb

Constant Summary collapse

VERSION =
"0.1.2"

Instance Method Summary collapse

Instance Method Details

#generate(strength = 8) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/random/password.rb', line 4

def generate(strength = 8)
  strength = strength.to_i
  # create a one big array of seeding data
  seed = [('a'..'z'), ('!'..'+'), (1..9), ('A'..'Z')].map { |e| e.to_a }.flatten
  # get random 16 characters from this array
  original = (0...strength).map { seed[rand(seed.length)] }.join
  # just to be sure, randomize them once more
  original.reverse!.split('').shuffle.join
end