密码强度判断条件如下:密码长度小于6,则强度为“弱”。在密码长度大于等于 6 的情况下,若只出现一种字符,则密码强度为“弱”;若出现两种不同字符,则密码强度为“中”,出现3种以上不同字符,则密码强度为“强”。
Private Sub Cmd1_Click()
Dim n As Integer, i As Integer, m As Integer, s As String, c As String
If n < 6 Then
Label3.Caption = "弱"
Else
s = "0000"
For i = 1 To n
c = Mid(Text1.Text, i, 1)
If c >= "0" And c <= "9" Then
Mid(s, 4, 1) = "1" '将字符串 s 第 4 位上的字符替换为"1"
ElseIf c >= "A" And c <= "Z" Then
Mid(s, 3, 1) = "1"
ElseIf c >= "a" And c <= "z" Then
Else
Mid(s, 1, 1) = "1"
End If
Next i
m = 0
For i = 1 To 4
If Mid(s, i, 1) = "1" Then
Next i
If m < 2 Then
Label3.Caption = "弱"
ElseIf m = 2 Then
Label3.Caption = "中"
Else
Label3.Caption = "强"
End If
End If
End Sub