登录验证程序出错!
vb.rar
(8.4 KB)
Const maxlogtimes As Integer = 3
Private Sub Command1_Click()
Static intlogtimes As Integer
Dim intcheck As Integer, strname As String, strpassword As String
intlogtimes = intlogtimes + 1
If intlogtimes > maxlogtimes Then
MsgBox "你已经超过允许验证次数!" & vbCr & "应用程序将结束", vbCritical, "登录验证"
End
Else
strname = Trim(Text1.Text)
strpassword = Trim(Text2.Text)
Select Case check_password(strname, strpassword)
Case 0
MsgBox "非法登录", vbCritical, "登录验证"
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1)
Case 1
MsgBox "密码错误,请重新输入", vbCritical, "登录验证"
Text2.Text = ""
Text2.SetFocus
Case 2
Unload Me
MsgBox "登录成功", vbInformation, "登录验证"
End Select
End If
End Sub
Private Sub Command2_Click()
intresult = MsgBox("您选择了退出登录系统!" & vbCrLf & "是否真的退出?", vbYesNo, "登录验证")
If intresult = vbYes Then End
End Sub
Private Function check_password(ByVal username As String, ByVal password As String) As Byte
On Error GoTo gperror
Dim objCn As New Connection, objRs As New Recordset, strcn As String
Dim strSQL As String
objCn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;" & _
"Data Source=" & App.Path & "db1.mdb"
objCn.Open
strSQL = "SELECT 口令 FROM 系统用户 WHERE 用户名='" & username & "'"
Set objRs.ActiveConnection = objCn
objRs.Open (strSQL)
If objRs.EOF Then
check_password = 0
Else
If password <> Trim(objRs.Fields("口令").Value) Then
check_password = 1
Else
check_password = 2
End If
End If
objCn.Close
Set objRs = Nothing
Set objCn = Nothing
Exit Function
gperror:
check_password = 255
Set objRs = Nothing
Set objCn = Nothing
End Function
这是我写的一个登录验证程序,有错误,但是我找不出来,麻烦大家给指正一下
[
[[it] 本帖最后由 xiaolaba3330 于 2008-4-13 12:49 编辑 [/it]]