Generate Memorable Passwords, Automatically!
Generating automatic passwords for your users is a common programming scenario. However, due to the techniques typically employed, most autogenerated passwords end up looking like YPSWW9441—which, although highly secure, also end up completely unmemorable.
The following function generates a password using alternating friendly consonants and vowels, making for much more memorable passwords. Asking the function to generate a five-character password, for example, may result in BONES or LAMOT.
To use this function, call GeneratePassword, passing in the length of your desired password. The final password will be returned as a string:
Public Function GeneratePassword(ByVal Length As Integer) As String ' Creates a memorable password of the specified Length Dim blnOnVowel As Boolean Dim strTempLetter As String Dim strPassword As String Dim intCount As Integer For intCount = 1 To Length If blnOnVowel = False Then ' Choose a nice consonant - no C, X, Z, or Q strTempLetter = CType(Choose(CType(GetRandomNumber(1, _ 17), _ Double), _ "B", "D", "F", "G", "H", "J", "K", "L", "M", _ "N", "P", "R", "S", "T", "V", "W", "Y"), String) ' Append it to the password string strPassword += strTempLetter ' Swich to vowel mode blnOnVowel = True Else ' Choose a vowel strTempLetter = CType(Choose(CType(GetRandomNumber(1, 5), _ Double), _ "A", "E", "I", "O", "U"), String) ' Append it to the password string strPassword += strTempLetter ' Switch back again, ready for next loop round blnOnVowel = False End If Next Return strPassword End Function Dim objRandom As New System.Random(CType((System.DateTime.Now. _ Ticks _ Mod System.Int32.MaxValue), Integer)) Public Function GetRandomNumber(Optional ByVal Low As Integer _ = 1, _ Optional ByVal High As Integer = 100) As Integer ' Returns a random number, ' between the optional Low and High parameters Return objRandom.Next(Low, High + 1) End Function
You could use the GeneratePassword function as so:
Dim MyPassword As String MyPassword = GeneratePassword(5) MessageBox.Show(MyPassword)
About the Author
Karl Moore (MCSD, MVP) is an experience author living in Yorkshire, England. He is author of numerous technology books, including the new Ultimate VB .NET and ASP.NET Code Book (ISBN 1-59059-106-2, $49.99), plus regularly features at industry conferences and on BBC radio. Moore also runs his own creative consultancy, White Cliff Computing Ltd. Visit his official Web site at www.karlmoore.com.

Comments
It is an old heat - even DEC VMS back in 197x had this feature
Posted by slacer on 03/24/2004 09:13amIt did not only generate the password - it shows how to memorize it: me-lo-pan-til And it checked the generated password against a dictionary - to avoid such easy passwords like BONES. Best regards, Michael
ReplyMore on numbers
Posted by PerFnurt on 03/22/2004 03:54pmYou could also use numbers as letters, like 0 instad of O, l instead of L, 3 instead of E etc to get a larger range of chars to use....
ReplyTack a number at the beginning or end
Posted by KevinHall on 03/22/2004 02:56pmYou would increase the number of passwords if you also allowed numbers (say 1 or 2 digits -- or even without digits) to exist at the beginning or end of the password. For example: kat74 4bona bones (if the parameter for digits was randomly chosen to be zero) It'd be quite simple to modify your code. Your idea is a very good one (and I'm glad you posted the article) -- I just thought that adding some digits could offer more possiblities without making a password that much more difficult to remember.
Reply