12-06-2011, 10:09 AM
Code:
Function GeneratePassword(Byval Length)
If (Length < 5) Then
Length = 5 'Do not allow a password of length less than 5
End If
Dim alphabet As String() = Split("a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z", ",") 'Declare Our Alphabet
Dim numbers As String() = Split("0,1,2,3,4,5,6,7,8,9", ",") 'Declare our numbers
Dim Symbols As String() = Split("!,£,$,%,^,&,*,(,),{,},~,@,:,;,#,?,/,>,.,<", ",") 'Declare our symbols
Dim Rand As New Random 'Declare our random
Dim Password As String = "" ''Decalre our password as an empty string
While (Password.Length() < length)
If (Password.Length() = (length - 1)) Then
Password += Symbols((Rand.Next(0, UBound(Symbols))))
ElseIf Password.Length() >= (length - 3) Then
Password += numbers(Rand.Next(0, UBound(numbers)))
Else
Password += alphabet(Rand.Next(0, UBound(alphabet)))
End If
End While
Return Password
End Function
After making the PHP version of this password generator (Which can be found here) I decided that I wanted to create a VB.Net version.
Usage:
PHP Code:
GeneratePassword(Length)
Example:
PHP Code:
GeneratePassword(15)
Output: xBUFaMJOtoTK45(
Enjoy.