Skip to content

Instantly share code, notes, and snippets.

@johana-star
Created August 5, 2012 18:55
Show Gist options
  • Save johana-star/3266680 to your computer and use it in GitHub Desktop.
Save johana-star/3266680 to your computer and use it in GitHub Desktop.
A simple password generator
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