Hamish Rickerby

Technology Consultant & iOS Developer based in Sydney, Australia

Mnemonic Password Generator - a La Ruby

| Comments

I wanted to have a mnenonic password generator for a little application that I’m writing in ruby, and couldn’t find one out there. So, I rolled my own. Actually, it’s a knock-off of a Python one I found, but that doesn’t really matter.

Do with this what you will. Hope it’s useful to someone.

1
2
3
4
5
6
7
8
9
10
11
12
13
def generateMnemonicPassword(letters=8, digits=4)
consonants = "bdfghklmnprstvwz"
vowels = "aeiou"
password = ""
(1 .. letters).each do |i|
range = i%2 == 1 ? consonants : vowels
password = password + range[rand(range.length), 1]
end
(1 .. digits).each do |i|
password = password + rand(10).to_s
end
password
end

It outputs fun and pronounceable passwords such as tepelopu8058, vonobuba6145 and kipowetu0270.

Enjoy!

Comments