(C#) Generate random readable passwords

By | July 9, 2013

Here’s a super simple function that generates humanly readable passwords by weaving random consonants and wovels.

The generated passwords are by no means secure. I did this for an application used to launch game servers and wanted to make the passwords be easy to communicate over Skype.

The two string constants may of course be edited to give a wider selection of characters, thus making it more secure. In my example I have stayed in lower case and removed some letters that makes passwords either hard to remember or ambiguous when pronounced.

Somehow it all looks like Swahili when building words like this…

public string CreateRandomPassword(int passwordLength)
        {
            const string consonants = "bdfghjklmnprstvy";
            const string wovels = "aeiou";

            var password = "";
            var randomNum = new Random();

            while (password.Length < passwordLength)
            {
                password += consonants[randomNum.Next(consonants.Length)];
                if (password.Length < passwordLength)
                    password += wovels[randomNum.Next(wovels.Length)];
            }

            return password;
        }

Calling it like this will give you a five character random word:

myString = CreateRandomPassword(5);

Leave a Reply

Your email address will not be published. Required fields are marked *