Friend Module PasswordGenerator
''' <summary>
''' Generates a random Password.
''' </summary>
''' <param name="Digits">The Maximum-Length of the Password.</param>
''' <returns></returns>
''' <remarks></remarks>
Public Function Generate(ByVal Digits As Integer) As String
'Alle Variationen.
Dim Variations As String = "abcdefghijklmnopqrstuvwxyz123456789#*$€"
'Neue StringBuilder/Random Instanz.
Dim Sb As New StringBuilder
Dim xy As New Random()
'Random-Boolean Funktion für das Upper/Lower Verfahren.
Dim RandomBoolean As New Func(Of Boolean)(Function()
Return xy.Next(0, 2) = 0
End Function)
'Zufällige Zeichen hinzufügen.
For i As Integer = 0 To Digits
'Char zwischenspeichern.
Dim C As Char = Variations(xy.Next(Variations.Length))
'Per Zufall entscheiden, ob das Char Groß/Klein ist.
If Not RandomBoolean.Invoke() Then
Sb.Append(C)
Else
Sb.Append(Char.ToUpper(C))
End If
Next
'Sicher stellen das Raute,Stern etc. wegen der Komplexität nur 1x vorkommen.
Return Sb.ToString.TrimEnd({"#"c, "*"c, "$"c, "€"c})
End Function
End Module