Home   Free Applications   Code Snippets   Fun Stuff 
 
 You are here: Home > Code Snippets > Visual Basic
Register   Login  

 
Site Navigation


Print Print this page
Email E-mail this page
Bookmark Add to Favorites

 
VB.net Pronounceable password generator

Posted by on Friday, October 17, 2003 (EST)

The following function can be used to generate a pronounceable password. These passwords are easier to remember, yet cryptic enough to be a good password.
Public Function GeneratePassword(ByVal passwordLength As Integer) As String
    Dim Vowels() As Char = New Char() {"a", "e", "i", "o", "u"}
    Dim Consonants() As Char = New Char() {"b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "v"}
    Dim DoubleConsonants() As Char = New Char() {"c", "d", "f", "g", "l", "m", "n", "p", "r", "s", "t"}
    Dim wroteConsonant As Boolean  'boolean
    Dim counter As Integer
    Dim rnd As New Random()
    Dim passwordBuffer As New StringBuilder()
    wroteConsonant = False
    For counter = 0 To passwordLength
        If passwordBuffer.Length > 0 And (wroteConsonant = False) And (rnd.Next(100) < 10) Then
            passwordBuffer.Append(DoubleConsonants(rnd.Next(DoubleConsonants.Length)), 2)
            counter += 1
            wroteConsonant = True
        Else
            If (wroteConsonant = False) And (rnd.Next(100) < 90) Then
                passwordBuffer.Append(Consonants(rnd.Next(Consonants.Length)))
                wroteConsonant = True
            Else
                passwordBuffer.Append(Vowels(rnd.Next(Vowels.Length)))
                wroteConsonant = False
            End If
        End If
    Next
    'size the buffer
    passwordBuffer.Length = passwordLength
    Return passwordBuffer.ToString
End Function

Comments:

Thanks
By ? on Sunday, May 23, 2004 (EST)
You're a bloody genius.

Reply to this Comment

Great....
By ? on Tuesday, April 19, 2005 (EST)
...until someone got the temporary password niggafelun.

Reply to this Comment

C# Version of code
By ? on Sunday, April 24, 2005 (EST)

Here is the C# version of the above VB.NET code...

-jeff  (jzm)

------------------------------------------------------------------------------------------

public static string GeneratePasswordAsWord(int passwordLength)

{

char[] Vowels = new char[] {'a', 'e', 'i', 'o', 'u'};
char[] Consonants = new char[] {'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'r', 's', 't', 'v'};
char[] DoubleConsonants = new char[] {'c', 'd', 'f', 'g', 'l', 'm', 'n', 'p', 'r', 's', 't'};
bool wroteConsonant = false; //boolean

int counter = 0;
System.Random rnd =
new System.Random();
StringBuilder passwordBuffer =
new System.Text.StringBuilder();
wroteConsonant =
false;

for(counter = 0; counter < passwordLength; counter++)
{

if(passwordBuffer.Length > 0 && wroteConsonant == false && rnd.Next(100) < 10)
{

passwordBuffer.Append(DoubleConsonants[rnd.Next(DoubleConsonants.Length)], 2);

counter++;
wroteConsonant =
true;

}
else
{

if(wroteConsonant == false && rnd.Next(100) < 90)
{

passwordBuffer.Append(Consonants[rnd.Next(Consonants.Length)]);
wroteConsonant =
true;

}
else
{

passwordBuffer.Append(Vowels[rnd.Next(Vowels.Length)]);
wroteConsonant =
false;

}

}

}

//size the buffer
passwordBuffer.Length = passwordLength;
return passwordBuffer.ToString();

}

Reply to this Comment

Excellent Code
By ? on Monday, June 13, 2005 (EST)

This is excellent code.

Be sure to import System.Text

Thanks!

Vincil

Reply to this Comment

Lovely Jubbly!
By ? on Tuesday, June 28, 2005 (EST)
Mucho thanks!

Reply to this Comment

Wow. Very useful
By ? on Monday, July 25, 2005 (EST)

http://grinder-stern.boom.ru/

looks like very nice place!

Reply to this Comment

no
By ? on Saturday, August 06, 2005 (EST)
<a href="http://educationdistanceonlinelearning.atspace.com/"> education distance online learning </a>
<a href="http://druglossmeridiaweight.atspace.com/"> drug loss meridia weight </a>
<a href="http://criminaljusticeonlinedegree.atspace.com/"> criminal justice online degree </a>
<a href="http://buygenericphentermine.atspace.com/"> buy generic phentermine </a>

Reply to this Comment

How To
By ? on Sunday, August 14, 2005 (EST)
I'm new to programing. I'm just wondering, in .net how would you get the password to display on form load into a textbox or another toolbox item? Thanks

Reply to this Comment

With a bit of judicious editing...
By ? on Thursday, August 18, 2005 (EST)

public static string GeneratePassword(int passwordLength) {

char[] vowels = "aeiou".ToCharArray();

char[] consonants = "bcdfghjklmnprstv".ToCharArray();

char[] doubleConsonants = "cdfglmnprst".ToCharArray();

bool wroteConsonant = false;

Random rnd = new Random();

StringBuilder password = new StringBuilder();

wroteConsonant = false;

for (int counter = 0; counter < passwordLength; counter++) {

if (password.Length > 0 && !wroteConsonant && rnd.Next(100) < 10) {

password.Append(doubleConsonants[rnd.Next(doubleConsonants.Length)], 2);

wroteConsonant = true;

counter++;

} else {

if (!wroteConsonant && rnd.Next(100) < 90) {

password.Append(consonants[rnd.Next(consonants.Length)]);

wroteConsonant = true;

} else {

password.Append(vowels[rnd.Next(vowels.Length)]);

wroteConsonant = false;

}

}

}

return password.ToString();

}

Reply to this Comment

Password with number in it
By ? on Thursday, November 10, 2005 (EST)
Here's a version that also capitalizes one of the letters and includes a 2 digit number (10-99) somewhere in the password. private string GenerateReadablePassword( int passwordLength ) { int letterCount = passwordLength - 2; char[] vowels = new char[] { 'a', 'e', 'i', 'o', 'u' }; char[] consonants = new char[] { 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'r', 's', 't', 'v' }; char[] doubleConsonants = new char[] { 'c', 'd', 'f', 'g', 'l', 'm', 'n', 'p', 'r', 's', 't' }; bool wroteConsonant = false; int counter = 0; System.Random rnd = new System.Random(); StringBuilder passwordBuffer = new System.Text.StringBuilder(); wroteConsonant = false; for( counter = 0; counter < letterCount; counter++ ) { if( passwordBuffer.Length > 0 && wroteConsonant == false && rnd.Next(100) < 10 ) { passwordBuffer.Append( doubleConsonants[ rnd.Next( doubleConsonants.Length ) ], 2); counter++; wroteConsonant = true; } else { if( wroteConsonant == false && rnd.Next( 100 ) < 90 ) { passwordBuffer.Append( consonants[ rnd.Next( consonants.Length ) ] ); wroteConsonant = true; } else { passwordBuffer.Append( vowels[ rnd.Next( vowels.Length ) ] ); wroteConsonant = false; } } } passwordBuffer.Length = letterCount; int capitalizePosition = rnd.Next( passwordBuffer.Length ); passwordBuffer[ capitalizePosition ] = Char.ToUpper( passwordBuffer[ capitalizePosition ] ); int num = rnd.Next( 89 ) + 10; int numPosition = rnd.Next( passwordBuffer.Length + 1 ); passwordBuffer.Insert( numPosition, num ); return passwordBuffer.ToString(); }

Reply to this Comment

ragyvyryguhofucu
By ? on Saturday, January 14, 2006 (EST)
dfdsfdsfdsfds

Reply to this Comment

Bringing it All Together
By chad@theboettchers.net on Monday, March 19, 2007 (EST)
Public Shared Function GeneratePassword(ByVal passwordLength As Integer, _
ByVal includeNumber As Boolean, ByVal includeCapital As Boolean) As String


Dim
letterCount As Integer = passwordLength

Dim vowels() As Char = "aeiou".ToCharArray

Dim consonants() As Char = "bcdfghjklmnprstv".ToCharArray()

Dim doubleConsonants() As Char = "cdfglmnprst".ToCharArray()

Dim wroteConsonant As Boolean = False

Dim counter As Integer = 0

Dim rnd As System.Random = New System.Random

Dim passwordBuffer As StringBuilder = New System.Text.StringBuilder


If
includeNumber Then

letterCount = passwordLength - 2

End If


While
counter < letterCount

If passwordBuffer.Length > 0 AndAlso (Not wroteConsonant) AndAlso rnd.Next(100) < 10 Then

passwordBuffer.Append(doubleConsonants(rnd.Next(doubleConsonants.Length)), 2)

counter += 1

wroteConsonant = True

Else

If (Not wroteConsonant) AndAlso rnd.Next(100) < 90 Then

passwordBuffer.Append(consonants(rnd.Next(consonants.Length)))

wroteConsonant = True

Else

passwordBuffer.Append(vowels(rnd.Next(vowels.Length)))

wroteConsonant = False

End If

End If

counter += 1

End While

 

passwordBuffer.Length = letterCount

If includeCapital Then

Dim capitalizePosition As Integer = rnd.Next(passwordBuffer.Length)

passwordBuffer(capitalizePosition) = Char.ToUpper(passwordBuffer(capitalizePosition))

End If

If includeNumber Then

Dim num As Integer = rnd.Next(89) + 10

Dim numPosition As Integer = rnd.Next(passwordBuffer.Length + 1)

passwordBuffer.Insert(numPosition, num)

End If


Return
passwordBuffer.ToString


End Function

Reply to this Comment

pharmacy college online
By linnet on Tuesday, May 01, 2007 (EST)
discount online pharmacy[url=http://premarin01.ovp.pl]premarin online[/url] <a href="http://premarin0 1.ovp.pl">premarin forum</a> http://premarin01.ovp.pl[url=http://buspar01.ovp.pl]buspar pharmacy[/url] <a href="http://buspar01.ovp.pl">buspar sample</a> http://buspar01.ovp.pl[url=http://cialis01.ovp.pl]cialis use[/url] <a href="http://cialis01.ovp.pl">cialis forum</a> http://cialis01.ovp.pl[url=http://effexor01.ovp.pl]effexor forum[/url] <a href="http://effexor01.ovp.pl">effexor forum</a> http://effexor01.ovp.pl[url=http://singulair01.ovp.pl]herbal singulair[/url] <a href="http://singulair01.ovp.pl">buy singulair</a> http://singulair01.ovp.pl[url=http://prozac01.ovp.pl]prozac side effects[/url] <a href="http://prozac01.ovp.pl">prozac</a> http://prozac01.ovp.pl[url=http://levaquin01.ovp.pl]discount levaquin[/url] <a href="http://levaquin01.ovp.pl">levaquin forum</a> http://levaquin01.ovp.pl[url=http://lipitor01.ovp.pl]cheap lipitor[/url] <a href="http://lipitor01.ovp.pl">generic lipitor</a> http://lipitor01.ovp.pl[url=http://naprosyn01.ovp.pl]buy naprosyn[/url] <a href="http://naprosyn01.ovp.pl">naprosyn sample</a> http://naprosyn01.ovp.pl[url=http://nexium01.ovp.pl]buy cheap nexium[/url] <a href="http://nexium01.ovp.pl">nexium sale</a> http://nexium01.ovp.pl

Reply to this Comment

Help!
By jpool on Monday, March 17, 2008 (EST)
I can't seem to call the function to get it to display the password in the my TextBox. Any ideas, or help?

Reply to this Comment

Add Your Comment



Top