Based on the mentioned evaluation with percentage progress, I made a small revision and now organized the output of the counts of the individual tests using a user-defined type.
I think this is very clear and easily expandable for additional tests.
Code:
Public Type PWElements
LenPW As Long
Numbers As Long
Uppercase As Long
Lowercase As Long
SpecialCharacter As Long
Repeat4 As Long
Consecutive4 As Long
End Type
Public Function TestPassword(sPW As String) As PWElements
Dim bytArrPW() As Byte
Dim sDiff() As String
Dim lCount As Long
Dim sSeries As String
Dim i As Long
Dim lNumber As Long
Dim lUppercase As Long
Dim lLowercase As Long
Dim lSpecialCharacter As Long
Dim myPWE As PWElements
bytArrPW() = StrConv(sPW, vbFromUnicode)
lCount = UBound(bytArrPW)
ReDim sDiff(lCount)
For i = 0 To lCount
Select Case bytArrPW(i)
Case 48 To 57
lNumber = lNumber + 1
Case 65 To 90
lUppercase = lUppercase + 1
Case 97 To 122
lLowercase = lLowercase + 1
Case 33 To 47, 58 To 64, 91 To 96
lSpecialCharacter = lSpecialCharacter + 1
End Select
Next
myPWE.LenPW = Len(sPW)
myPWE.Numbers = lNumber
myPWE.Uppercase = lUppercase
myPWE.Lowercase = lLowercase
myPWE.SpecialCharacter = lSpecialCharacter
For i = 1 To lCount
sDiff(i) = CLng(bytArrPW(i)) - CLng(bytArrPW(i - 1))
Next
sSeries = Join(sDiff, "|")
myPWE.Repeat4 = UBound(Split(sSeries, "0|0|0|"))
myPWE.Consecutive4 = UBound(Split(sSeries, "1|1|1|"))
TestPassword = myPWE
End Function
Code:
Sub call_TestPW()
Dim xPWE As PWElements
xPWE = TestPassword("<TaaaaB2345%d@x")
Debug.Print xPWE.LenPW, _
xPWE.Numbers, _
xPWE.Uppercase, _
xPWE.Lowercase, _
xPWE.SpecialCharacter, _
xPWE.Repeat4, _
xPWE.Consecutive4
End Sub
I think this is very clear and easily expandable for additional tests.
Last edited: