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