Class: PasswordGenerator
- Inherits:
-
Object
- Object
- PasswordGenerator
- Defined in:
- lib/lockr/pwdgen.rb
Instance Method Summary collapse
Instance Method Details
#generate(params) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/lockr/pwdgen.rb', line 5 def generate( params) pwd = [] # create x random characters params.to_i.times do l = SecureRandom.random_number(26) pwd << l end # up/downcase with 50% chance pwd.collect!{ |i| (i + 65).chr }.collect!{ |c| if ( SecureRandom.random_number(0) > 0.5) c.downcase else c end } pwd.join end |