Complex Password Generator in VB.Net

Post date: Oct 6, 2015 8:10:15 PM

I couldn't find a good Complex Password Generator in VB.Net so I wrote my own.

Private Function randomPassword(passedLength As Integer)

Dim myLowercase As String = "abcdefghijklmnopqrstuvwxyz"

Dim myUppercase As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

Dim myNumbers As String = "0123456789"

Dim mySymbols As String = "~!@#$^*()_-+={}[]:;<>,.?/"

Dim myAllChars As String = myLowercase & myUppercase & myNumbers & mySymbols

Dim myRandom As New System.Random

Dim myPassword As String = ""

myPassword = myPassword & myLowercase(myRandom.Next(0, myLowercase.Length)) & myLowercase(myRandom.Next(0, myLowercase.Length))

myPassword = myPassword & myUppercase(myRandom.Next(0, myUppercase.Length)) & myUppercase(myRandom.Next(0, myUppercase.Length))

myPassword = myPassword & myNumbers(myRandom.Next(0, myNumbers.Length)) & myNumbers(myRandom.Next(0, myNumbers.Length))

myPassword = myPassword & mySymbols(myRandom.Next(0, mySymbols.Length)) & mySymbols(myRandom.Next(0, mySymbols.Length))

For i As Integer = 0 To (passedLength - 9)

myPassword = myPassword & myAllChars(myRandom.Next(0, myAllChars.Length))

Next

Dim strInput As String = myPassword

Dim strOutput As String = ""

Dim rand As New System.Random

Dim intPlace As Integer

While strInput.Length > 0

intPlace = rand.Next(0, strInput.Length)

strOutput += strInput.Substring(intPlace, 1)

strInput = strInput.Remove(intPlace, 1)

End While

myPassword = strOutput

Return myPassword

End Function

Needed a simple query in MySQL too:

SELECT LEFT(GROUP_CONCAT(ELT(1 + FLOOR(RAND()*83),'!','@','#','$','^','&','*','_','-','=','+','!','@','#','$','^','&','*','_','-','=','+','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','0','1','2','3','4','5','6','7','8','9','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') SEPARATOR ''),14) AS randompass FROM [any existing table here]