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.



About the Author

Karl Moore

Karl Moore (MCSD, MVP) is an experience author living in Yorkshire, England. He is the author of numerous technology books, including the new Ultimate VB .NET and ASP.NET Code Book (ISBN 1-59059-106-2), 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:13am

    It 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

    Reply
  • More on numbers

    Posted by PerFnurt on 03/22/2004 03:54pm

    You 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....

    Reply
  • Tack a number at the beginning or end

    Posted by KevinHall on 03/22/2004 02:56pm

    You 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
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: September 10, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild". This loop of continuous delivery and continuous feedback is …

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds