Guest User

Untitled

a guest
Feb 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. # minimum length for a password
  4. MINIMUM_LENGTH = 4
  5. # default length if not specified on command line
  6. DEFAULT_LENGTH = 16
  7. # sets of characters to use - don't use 0 and 1 to avoid confusion with O and I
  8. CHARACTER_SETS = [('A'..'Z'),('a'..'z'),('2'..'9')]
  9.  
  10. # don't change this
  11. characters = CHARACTER_SETS.collect{|set| set.collect{|character| character}}.flatten
  12.  
  13. length = (ARGV[0] || DEFAULT_LENGTH).to_i
  14. raise ArgumentError, "length of #{length} is too short" unless length >= MINIMUM_LENGTH
  15.  
  16. password = (0..length-1).inject(''){|pw, n| pw + characters[rand(characters.length)] }
  17. puts password
Add Comment
Please, Sign In to add comment