> ' Generate a password with alpha characters > ' expN1 Length of the password > Public Function GeneratePasswordAlpha(ByVal tnLength As Integer) As String > Dim lcPassword As String = "" > Dim llWroteConsonant As Boolean = False > Dim lnCounter As Integer = 0 > Dim lnNext As Integer = 0 > Dim lnOldValue As Integer = 0 > Dim loConsonants() As Char = New Char() {"b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "v"} > Dim loDoubleConsonants() As Char = New Char() {"c", "d", "f", "g", "l", "m", "n", "p", "r", "s", "t"} > Dim loPasswordBuffer As New System.Text.StringBuilder > Dim loRnd As Random = New Random > Dim loVowels() As Char = New Char() {"a", "e", "i", "o", "u"} > > ' The use of a static approach here is to avoid loRnd to obtain the same value > ' if we call it twice in a row. The random seed could not be fast enough thus, we > ' have to verify on the previous value and random seed it again to obtain a new value. > Static loRandomValue As Random = New Random > > lnNext = loRnd.Next(100) > lnOldValue = loRandomValue.Next(100) > > If lnNext = lnOldValue Then > > ' Wait for a timeout before retrying > System.Threading.Thread.Sleep(3) > > lnNext = loRnd.Next(100) > End If > > For lnCounter = 0 To tnLength > If loPasswordBuffer.Length > 0 And Not llWroteConsonant And loRnd.Next(100) < 10 Then > loPasswordBuffer.Append(loDoubleConsonants(loRnd.Next(loDoubleConsonants.Length)), 2) > lnCounter = lnCounter + 1 > llWroteConsonant = True > Else > If Not llWroteConsonant And loRnd.Next(100) < 90 Then > loPasswordBuffer.Append(loConsonants(loRnd.Next(loConsonants.Length))) > llWroteConsonant = True > Else > loPasswordBuffer.Append(loVowels(loRnd.Next(loVowels.Length))) > llWroteConsonant = False > End If > End If > Next > > ' Size the buffer > loPasswordBuffer.Length = tnLength > > Return loPasswordBuffer.ToString > End Function >