Dim num As Integer   '记录输入密码次数
Dim f As String
Dim a As ADODB.Recordset
Dim zhb As String
Dim n As Integer
Private Sub Cmd1_Click()
    Dim Encode As String
    Dim txtsql As String
    Dim mrc As ADODB.Recordset
    
    If Len(username.Text) = 0 Then   '判断输入是否为空
        MsgBox "请输入用户名!", vbOKOnly + vbExclamation, "通讯录--提示"
       username.SetFocus
    ElseIf Len(userpassword.Text) = 0 Then
        MsgBox "请输入密码!", vbOKOnly + vbExclamation, "通讯录--提示"
       userpassword.SetFocus
    Else
        txtsql = "select * from user_info where 用户名 = '" & Trim(username.Text) & "'"  '检验输入用户名是否存在
        Set mrc = ExecuteSQL(txtsql)

        
        If mrc.RecordCount = 0 Then
            MsgBox "该用户名不存在,请重新输入!", vbOKOnly + vbExclamation, "通讯录--提示"
            username.SetFocus
            username.Text = ""
            mrc.Close
            Exit Sub
        End If
       qy = mrc("权限")
       user_id = mrc("用户名")        Encode = EncodePassWord(Trim(userpassword.Text))  '调用加密函数
        
        txtsql = "select * from user_info where 密码 = '" & Trim(Encode) & "'"   '检验输入的密码是否正确
        Set mrc = ExecuteSQL(txtsql)
        
        If mrc.RecordCount = 0 Then
            MsgBox "密码不正确,请重新输入!", vbOKOnly + vbExclamation, "通讯录--提示"
            num = num + 1
          
             userpassword.Text = ""
              userpassword.SetFocus
            If num = 3 Then
                MsgBox "由于多次输入错误,系统将自动关闭,如果你 忘记密码请速与管理员联系!", vbOKOnly + vbInformation, "通讯录--注意"
                End
            End If
        Else
           zhb = EncodePassWord(Trim(userpassword.Text))
            f = "SELECT * from  user_info where 用户名='" & Trim(username.Text) & "' and 密码='" & Trim(zhb) & "'"
            Set a = ExecuteSQL(f)
            If Not (a.EOF Or a.BOF) Then            '全部检验正确,进入主窗体
          
           usernames = username.Text
            Unload Me
            'useradd.Show
            'reworkpassword.Show
            zhumain.Show
            Else
            MsgBox "对不起!输入密码错误!你此次输入了非法字符!请查证后再重新输入!", vbCritical, "提示"
            n = n + 1
            If n = 3 Then
            MsgBox "输入达到3次,输入已经上限!程序即将结束!", , "提示"
            Unload Me
            End If
            End If
            
        End If
    End If
End Sub
Private Sub Cmd2_Click()
End
End SubPrivate Sub Label3_Click()
newuseradd.Show
End SubPrivate Sub Label3_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If Label3.FontUnderline = False Then
    Label3.FontUnderline = True
    Else
     Label3.FontUnderline = False
     End If
End Sub
Private Sub userpassword_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
Call Cmd1_Click
End If
End Sub
Private Sub Form_Load()
    Me.Width = 1
    Timer1.Interval = 100
End SubPrivate Sub Timer1_Timer()
    If login.Width < 5000 Then
       login.Width = login.Width + 500
    End If
End Sub

解决方案 »

  1.   

    lz这个代码也是够蛋疼的,用户名和密码干嘛不一次性进行验证,而要分成好几次进行?zhb = EncodePassWord(Trim(userpassword.Text))
    f = "SELECT * from  user_info where 用户名='" & Trim(username.Text) & "' and 密码='" & Trim(zhb) & "'"
    Set a = ExecuteSQL(f)
    if a.recordcount>0 then
      验证正确
    else
      验证错误,。
    end if