Indicate Password strength to User

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've a procedure (given below) that attempts to indicate Password strength to
User who wants to change his/her log on Password. But, I'm not convinced
about the elegance of this procedure.

Can someone help me with a better code ?


Private Sub Password_AfterUpdate()
On Error GoTo Err_PasswordAfterUpdate

Dim i As Integer
Dim counter As Integer
Dim AscTest As Integer
Dim AscResult As Integer
Dim SplChar As Integer
Dim ModResult As Integer

'Get the length of the Password
counter = Len(Trim(Me!Password))

For i = 1 To counter
AscTest = Asc(Mid(Me!Password, i, 1))
'Find if user enters Alphabets
If (AscTest >= 65) And (AscTest <= 122) Then
AscResult = AscResult + 1
End If
'Find if user enters Numbers
If (AscTest >= 48) And (AscTest <= 57) Then
AscResult = AscResult + 2
End If
Next i

For i = 1 To counter
AscTest = Asc(Mid(Me!Password, i, 1))
'Find if user enters Special Characters
If (((AscTest >= 33) And (AscTest <= 47)) Or _
((AscTest >= 58 And (AscTest <= 64)))) Then
SplChar = SplChar + 1
End If
Next i

ModResult = AscResult Mod counter

If SplChar = 0 Then
If ModResult = 0 Then
'User is using only Alphabets or only Numbers
'Code to indicate that Password Strength is "WEAK"
Else
'User entered a combination of Alphabets and Numbers only
'Code that returns Password Strength as "MEDIUM"
End If
Else
'User also included a Special Character
'Code that returns Password Strength as "STRONG"
End If

Exit_PasswordAfterUpdate:
Exit Sub
Err_PasswordAfterUpdate:
ErrorLog "PasswordAfterUpdate", err, Error
Resume Exit_PasswordAfterUpdate

End Sub
 
I don't think Mod is going to give you what you want. If they've used an
even number of letters, Mod is going to be 0 whether or not they've also
used numbers.

Try the following untested air-code:

Private Sub Password_AfterUpdate()
On Error GoTo Err_PasswordAfterUpdate

Dim i As Integer
Dim intLetters As Integer
Dim intNumbers As Integer
Dim intSpecial As Integer
Dim strStrength As String

intLetters = 0
intNumbers = 0
intSpecial = 0

For i = 1 To Len(Trim(Me!Password))
Select Case Asc(Mid(Me!Password, i, 1))
Case 33 To 47
intSpecial = 1
Case 48 To 57
intNumbers = 1
Case 58 To 64
intSpecial = 1
Case 65 To 122
intLetters = 1
End Select
Next i

Select Case (intLetters + intNumbers + intSpecial)
Case 0
strStrength = "???"
Case 1
strStrength = "WEAK"
Case 2
strStrength = "MEDIUM"
Case 3
strStrength = "STRONG"
End Select

Exit_PasswordAfterUpdate:
Exit Sub
Err_PasswordAfterUpdate:
ErrorLog "PasswordAfterUpdate", err, Error
Resume Exit_PasswordAfterUpdate

End Sub
 
I've tested my code again and found that Mod definitely leaves a remainder if
User uses a combination of letters and numbers, no matter even or odd.

However, I must confess your code has simplified things to a great extent
and is definitely a better approach to what I've been trying.

Thanks a lot.
 
You might want to add a test for a minimum length also.

A1 - is not a very strong password.
 
Back
Top