This is the scheme i am using and it seems to work quite well.
Public Enum PasswordComplexityScore
BadPassword
MediumStrengthPassword
GoodPassword
End Enum
Public Function CalculatePasswordComplexity() As PasswordComplexityScore
Dim Score As Integer
'If the password matches the username then BadPassword
If Password = UserName Then
Return PasswordComplexityScore.BadPassword
End If
'If the password is less than 5 characters then TooShortPassword
If Password.Length < 5 Then
Return PasswordComplexityScore.BadPassword
End If
Score = Password.Length * 4
Score = Score + (CheckRepeatedPatterns(1).Length - Password.Length)
Score = Score + (CheckRepeatedPatterns(2).Length - Password.Length)
Score = Score + (CheckRepeatedPatterns(3).Length - Password.Length)
Score = Score + (CheckRepeatedPatterns(4).Length - Password.Length)
'If the password has 3 numbers then score += 5
If CountNumbers() >= 3 Then
Score = Score + 5
End If
'If the password has 2 special characters then score += 5
If CountSymbols() >= 2 Then
Score = Score + 5
End If
'If the password has upper and lower character then score += 10
If HasUpperAndLowerCharacters() Then
Score = Score + 10
End If
'If the password has numbers and characters then score += 15
If HasNumbersAndCharacters() Then
Score = Score + 10
End If
'If the password has numbers and special characters then score += 15
If CountNumbers() > 0 And CountSymbols() > 0 Then
Score = Score + 15
End If
'If the password has special characters and characters then score += 15
If CountLetters() > 0 And CountSymbols() > 0 Then
Score = Score + 15
End If
'If the password is only characters then score -= 10
If CountLetters() > 0 And CountNumbers() = 0 And CountSymbols() = 0 Then
Score = Score - 15
End If
'If the password is only numbers then score -= 10
If CountLetters() = 0 And CountNumbers() > 0 And CountSymbols() = 0 Then
Score = Score - 15
End If
If Score > 100 Then
Score = 100
End If
If Score < 34 Then
Return PasswordComplexityScore.BadPassword
End If
If Score < 68 Then
Return PasswordComplexityScore.MediumStrengthPassword
End If
Return PasswordComplexityScore.GoodPassword
End Function
I have been using this in production for about 8 years now. I think I converted it from someone elses java script into vb6 then into vb.net.
I can post all the supporting functions if you want.
Cheers