Abundant Technologies - IT Consulting Experts

 Source Code Library

 Code Details

 
Public Class random_Password Protected rGen As Random Protected strCharacters As String() = {"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", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "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"} Protected PASSWORD_LENGTH As Int32 = 8 Public Sub New() rGen = New Random End Sub Public Function GenPassWithCap(ByVal i As Int32) As String Dim p As Int32 = 0 Dim strPass As String = "" Dim x As Int32 For x = 1 To i p = rGen.Next(0, 60) strPass += strCharacters(p) Next Return strPass End Function Public Function GenPassLowercase(ByVal i As Int32) As String Dim p As Int32 = 0 Dim strPass As String = "" Dim x As Int32 For x = 1 To i p = rGen.Next(0, 35) strPass += strCharacters(p) Next Return strPass.ToLower() End Function Public Function GenStrongPassword() Dim tmpPassword As String = GenPassWithCap(PASSWORD_LENGTH) While Not IsStrong(tmpPassword) tmpPassword = GenPassWithCap(PASSWORD_LENGTH) End While Return tmpPassword End Function Public Function IsStrong(ByVal sPassword As String) As Boolean Dim i As Int32 Dim bPassedTest As Boolean 'password rule at least 8 characters If sPassword.Length < 8 Then Return False End If 'password rule at least 1 upper case bPassedTest = False For i = 0 To sPassword.Length - 1 If sPassword.Substring(i, 1) = sPassword.Substring(i, 1).ToUpper And Not IsNumeric(sPassword.Substring(i, 1)) Then bPassedTest = True Exit For End If Next If Not bPassedTest Then Return False End If 'password rule at least 1 lower case bPassedTest = False For i = 0 To sPassword.Length - 1 If sPassword.Substring(i, 1) = sPassword.Substring(i, 1).ToLower And Not IsNumeric(sPassword.Substring(i, 1)) Then bPassedTest = True Exit For End If Next If Not bPassedTest Then Return False End If 'password rule at least 1 number bPassedTest = False For i = 0 To sPassword.Length - 1 If IsNumeric(sPassword.Substring(i, 1)) Then bPassedTest = True Exit For End If Next If Not bPassedTest Then Return False End If Return True End Function End Class

Mail To: info@3pc.com