Created
August 5, 2012 18:55
-
-
Save johana-star/3266680 to your computer and use it in GitHub Desktop.
A simple password generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
words, password = [], '' | |
min_word_length, max_word_length, words_in_password = 4, 8, 4 + rand(2) | |
File.open("/usr/share/dict/words") do |file| | |
file.each do |line| | |
if line.length <= max_word_length and line.length >= min_word_length | |
words << line.strip.downcase | |
end | |
end | |
end | |
def spacer | |
array = Array(0..9) + ['!', '~', '-', '_', ' ', '+', '=', '%', '$', '#', '@'] | |
array.shuffle.first.to_s | |
end | |
words_in_password.times do | |
password += words.shuffle.first + spacer | |
end | |
password.chop! | |
puts password |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment