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: April 22, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Database professionals — whether developers or DBAs — can often save valuable time by learning to get the most from their new or existing productivity tools. Whether you're responsible for managing database projects, performing database health checks and reporting, analyzing code, or measuring software engineering metrics, it's likely you're not taking advantage of some of the lesser-known features of Toad from Dell. Attend this live …

  • Instead of only managing projects organizations do need to manage value! "Doing the right things" and "doing things right" are the essential ingredients for successful software and systems delivery. Unfortunately, with distributed delivery spanning multiple disciplines, geographies and time zones, many organizations struggle with teams working in silos, broken lines of communication, lack of collaboration, inadequate traceability, and poor project visibility. This often results in organizations "doing the …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds