我在SQL中建了一个数据库名叫test,里面放了一张表名叫load,表里存放用户ID,Name,和Password,然后做了一个登录的界面,输入用户名密码,点“登录”按钮,如果正确显示“登录成功”,错误显示“你输入的用户名或密码有误!”
这怎么做?
[此贴子已经被作者于2007-7-27 22:57:55编辑过]
我在SQL中建了一个数据库名叫test,里面放了一张表名叫load,表里存放用户ID,Name,和Password,然后做了一个登录的界面,输入用户名密码,点“登录”按钮,如果正确显示“登录成功”,错误显示“你输入的用户名或密码有误!”
这怎么做?
[此贴子已经被作者于2007-7-27 22:57:55编辑过]
 2007-07-26 20:31
	    2007-07-26 20:31
  Option Explicit
  Public conn As ADODB.Connection
Sub main()
    Set conn = New ADODB.Connection
     conn.ConnectionString = "rovider=MSDASQL.1ersist Security Info=False;" _
     + "User ID=sa;password=sa;Initial Catalog=myDb.mdb;Data Source= 10.173.0.231"
    conn.Open
from1.Show     '登录界面
End Sub
Private Sub Command1_Click()
    If Text1.Text = "" Then
        MsgBox "用户名不能为空!", vbOKOnly + vbInformation, "友情提示"
        Text1.SetFocus
        Exit Sub
    End If
    If Text2.Text = "" Then
        MsgBox "密码不能为空!", vbOKOnly + vbInformation, "友情提示"
        Text2.SetFocus
        Exit Sub
    End If
    Dim strSQl As String
    strSQl = "select * from load where Name='" & Trim$(Text1.Text) & "' and password='" & Trim$(Text2.Text) & "' "
    
    Dim str As New ADODB.Recordset
    Dim Try_times As Integer
    Set str = New ADODB.Recordset
    str.CursorLocation = adUseClient
    str.Open strSQl, conn, adOpenStatic, adLockReadOnly
    
    With str
        If .State = adStateOpen Then .Close
        .Open strSQl
        If .EOF Then
            Try_times = Try_times + 1
            If Try_times >= 3 Then
                MsgBox "您已经三次尝试进入本系统,均不成功,系统将自动关闭", vbOKOnly + vbCritical, "警告"
                Unload Me
            Else
                MsgBox "对不起,用户名不存在或密码错误 !", vbOKOnly + vbQuestion, "警告"
                Text1.SetFocus
                Text1.Text = ""
                Text2.Text = ""
            End If
        Else
            
            Unload Me
            
          Form2.Show    '登录进入的另一个界面
            
        End If
    End With
End Sub
Private Sub Command2_Click()
    End
End Sub
红色这句提示错误:
 
					
				
			
 2007-07-26 23:00
	    2007-07-26 23:00
   2007-07-27 11:57
	    2007-07-27 11:57
  改好了现在可以正常运行了,但是还是有个地方觉得不完美,希望高手来帮忙给改改!
我的这个现在限制了密码输入错误的次数为三次,用户名输入错误的次数也为三次
但是如果我先输错了2次密码,后又输入了2次错误的用户名,第5次如果输入的是错误的密码就提示“您已经连续三次输入错误密码,请查证后再进行登录!”,程序退出;如果输入的是错误的用户名就提示“您已经连续三次输入不存在的用户名,请查证后再进行登录!”,程序退出。这样感觉很不完善,如果能在第五次的时候不论是输入错误的密码还是错误的用户名都能给出一个新的提示“您已经连续五次输入了错误的用户名或密码!!!请进行查证!”,程序退出,这样多好,我弄了一下午也弄不出这个效果,谁能修改下我下面的代码把这个效果实现???
 
Option Explicit
Private gdbConn As New ADODB.Connection
Dim llCount As Long
Dim luCount As Long
Dim lsCount As Long
Private Sub Command1_Click()
    
    If Text1.Text = "" Then
        MsgBox "用户名不能为空!", vbOKOnly + vbInformation, "友情提示"
        Text1.SetFocus
        Exit Sub
    End If
    
    If Text2.Text = "" Then
        MsgBox "密码不能为空!", vbOKOnly + vbInformation, "友情提示"
        Text2.SetFocus
        Exit Sub
    End If
    
    Dim lrRec As New ADODB.Recordset
    Dim lsSql  As String
    
    lsSql = "select * from login where Name='" & Trim$(Text1.Text) & "'"
    
    gdbConn.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=CX;Initial Catalog=test"
    
    gdbConn.Open
    
    lrRec.Open lsSql, gdbConn, adOpenKeyset, adLockOptimistic
    
         If lrRec.RecordCount <> 0 Then
            
            If lrRec.Fields("Password") = Text2.Text Then
                Form2.Show
                Unload Me
                
            Else
                If llCount >= 2 Then
                    MsgBox "您已经连续三次输入错误密码,请查证后再进行登录!", vbExclamation + vbOKOnly, "登陆失败"
                    lrRec.Close
                    Unload Me
                    Exit Sub
                Else
                    llCount = llCount + 1
                    MsgBox "密码错误!请重新输入!", vbExclamation + vbOKOnly, "友情提示"
                    Text2.Text = ""
                    Text2.SetFocus
                    gdbConn.Close
                    Exit Sub
                End If
            End If
            
        Else
                If luCount >= 2 Then
                    MsgBox "您已经连续三次输入不存在的用户名,请查证后再进行登录!", vbExclamation + vbOKOnly, "登陆失败"
                    lrRec.Close
                    Unload Me
                    Exit Sub
                Else
                    luCount = luCount + 1
                    MsgBox "该用户不存在!请重新输入!", vbExclamation + vbOKOnly, "友情提示"
                    Text1.Text = ""
                    Text2.Text = ""
                    Text1.SetFocus
                    gdbConn.Close
                    Exit Sub
                End If
           Exit Sub
              
        End If
     Exit Sub
End Sub
    
Private Sub Command2_Click()
    Set gdbConn = Nothing
    Unload Me
End Sub

 2007-07-27 22:55
	    2007-07-27 22:55
  Option Explicit
Private gdbConn As New ADODB.Connection
Dim llCount As Long
Dim luCount As Long
Dim lsCount As Long
Private Sub Command1_Click()
    If Text1 = "" Then
        MsgBox "用户名不能为空!",vbInformation, "友情提示"
        Text1.SetFocus
        Exit Sub
    End If
    If Text2 = "" Then
        MsgBox "密码不能为空!",vbInformation, "友情提示"
        Text2.SetFocus
        Exit Sub
    End If
    Dim lrRec As New ADODB.Recordset
    Dim lsSql  As String
lsSql = "select * from login where Name='" & Trim$(Text1) & "'"
    gdbConn.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=CX;Initial Catalog=test"
    gdbConn.Open
    lrRec.Open lsSql, gdbConn, adOpenKeyset, adLockOptimistic
    If lrRec.RecordCount <> 0 Then
        If lrRec.Fields("Password") = Text2 Then
            Form2.Show
            Unload Me
        Else
            If llCount = 3 Then
                If luCount > 0 Then
                    lsSql = Mid("四五",luCount,1)
                    MsgBox "您已经连续" & lsSql & "次输入了错误的用户名或密码!!!请进行查证!",vbCritical,"登陆失败"
                Else
                    MsgBox "您已经连续三次输入错误密码,请查证后再进行登录!", vbExclamation, "登陆失败"
                End If
                lrRec.Close
                Unload Me
            Else
                llCount = llCount + 1
                MsgBox "密码错误!请重新输入!", vbExclamation, "友情提示"
                Text2 = ""
                Text2.SetFocus
                gdbConn.Close
            End If
        End If
    Else
        If luCount = 3 Then
            If llCount > 0 Then
                lsSql = Mid("四五",llCount,1)
                MsgBox "您已经连续" & lsSql & "次输入了错误的用户名或密码!!!请进行查证!",vbCritical,"登陆失败"
            Else
                MsgBox "您已经连续三次输入不存在的用户名,请查证后再进行登录!", vbExclamation, "登陆失败"
            End If
            lrRec.Close
            Unload Me
        Else
            luCount = luCount + 1
            MsgBox "该用户不存在!请重新输入!", vbExclamation, "友情提示"
            Text1 = ""
            Text2 = ""
            Text1.SetFocus
            gdbConn.Close
        End If
    End If
End Sub
'Exit Sub没有意义。。。Msgbox默认就是vbOKOnly不需要,恩,没有数据库环境你看着用,不行自己改下就是那个思路
[此贴子已经被作者于2007-7-28 0:22:48编辑过]

 2007-07-28 00:10
	    2007-07-28 00:10
  在这个例子里有完整的登陆界面。
压缩文件超过521K,不能上传,到我的站上下载。
http://www.lshsoft.net/lshbbs/dispbbs.asp?boardID=23&ID=305&page=1
看见大家那么辛苦的寻找,把我的一个小东西发给大家参考参考。
感觉有用处就顶一下。

 2007-07-28 09:34
	    2007-07-28 09:34
  Option Explicit
Private gdbConn As New ADODB.Connection
Dim llCount As Long
Dim luCount As Long
Dim lsCount As Long
Private Sub Command1_Click()
    If Text1 = "" Then
        MsgBox "用户名不能为空!",vbInformation, "友情提示"
        Text1.SetFocus
        Exit Sub
    End If
    If Text2 = "" Then
        MsgBox "密码不能为空!",vbInformation, "友情提示"
        Text2.SetFocus
        Exit Sub
    End If
    Dim lrRec As New ADODB.Recordset
    Dim lsSql  As String
lsSql = "select * from login where Name='" & Trim$(Text1) & "'"
    gdbConn.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=CX;Initial Catalog=test"
    gdbConn.Open
    lrRec.Open lsSql, gdbConn, adOpenKeyset, adLockOptimistic
    If lrRec.RecordCount <> 0 Then
        If lrRec.Fields("Password") = Text2 Then
            Form2.Show
            Unload Me
        Else
            If llCount = 3 Then
                If luCount > 0 Then
                    lsSql = Mid("四五",luCount,1)
                    MsgBox "您已经连续" & lsSql & "次输入了错误的用户名或密码!!!请进行查证!",vbCritical,"登陆失败"
                Else
                    MsgBox "您已经连续三次输入错误密码,请查证后再进行登录!", vbExclamation, "登陆失败"
                End If
                lrRec.Close
                Unload Me
            Else
                llCount = llCount + 1
                MsgBox "密码错误!请重新输入!", vbExclamation, "友情提示"
                Text2 = ""
                Text2.SetFocus
                gdbConn.Close
            End If
        End If
    Else
        If luCount = 3 Then
            If llCount > 0 Then
                lsSql = Mid("四五",llCount,1)
                MsgBox "您已经连续" & lsSql & "次输入了错误的用户名或密码!!!请进行查证!",vbCritical,"登陆失败"
            Else
                MsgBox "您已经连续三次输入不存在的用户名,请查证后再进行登录!", vbExclamation, "登陆失败"
            End If
            lrRec.Close
            Unload Me
        Else
            luCount = luCount + 1
            MsgBox "该用户不存在!请重新输入!", vbExclamation, "友情提示"
            Text1 = ""
            Text2 = ""
            Text1.SetFocus
            gdbConn.Close
        End If
    End If
End Sub
'Exit Sub没有意义。。。Msgbox默认就是vbOKOnly不需要,恩,没有数据库环境你看着用,不行自己改下就是那个思路
按照你说的做了一些修改,现在已经达到效果了。。。
非常感谢啊!!!
Option Explicit
Private gdbConn As New ADODB.Connection
Dim llCount As Long
Dim luCount As Long
Private Sub Command1_Click()
    
    If Text1.Text = "" Then
        MsgBox "用户名不能为空!", vbOKOnly + vbInformation, "友情提示"
        Text1.SetFocus
        Exit Sub
    End If
    
    If Text2.Text = "" Then
        MsgBox "密码不能为空!", vbOKOnly + vbInformation, "友情提示"
        Text2.SetFocus
        Exit Sub
    End If
    
    Dim lrRec As New ADODB.Recordset
    Dim lsSql  As String
    
    lsSql = "select * from login where Name='" & Trim$(Text1.Text) & "'"
    
    gdbConn.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=CX;Initial Catalog=test"
    
    gdbConn.Open
    
    lrRec.Open lsSql, gdbConn, adOpenKeyset, adLockOptimistic
    
         If lrRec.RecordCount <> 0 Then
            
            If lrRec.Fields("Password") = Text2.Text Then
                Form2.Show
                Unload Me
                
            Else
                If llCount = 2 Then
                    If luCount > 0 Then
                        lsSql = Mid("四五", luCount, 1)
                        MsgBox "您已经连续" & lsSql & "次输入了错误的用户名或密码!!!请进行查证!", vbCritical, "登陆失败"
                    Else
                        MsgBox "您已经连续三次输入错误密码,请查证后再进行登录!", vbExclamation + vbOKOnly, "登陆失败"
                    End If
                    lrRec.Close
                    Unload Me
                    
                Else
                    llCount = llCount + 1
                    MsgBox "密码错误!请重新输入!", vbExclamation + vbOKOnly, "友情提示"
                    Text2.Text = ""
                    Text2.SetFocus
                    gdbConn.Close
                End If
            End If
            
        Else
            If luCount = 2 Then
                If llCount > 0 Then
                    lsSql = Mid("四五", llCount, 1)
                    MsgBox "您已经连续" & lsSql & "次输入了错误的用户名或密码!!!请进行查证!", vbCritical, "登陆失败"
                Else
                    MsgBox "您已经连续三次输入不存在的用户名,请查证后再进行登录!", vbExclamation + vbOKOnly, "登陆失败"
                    End If
                    lrRec.Close
                    Unload Me
            Else
                luCount = luCount + 1
                MsgBox "该用户不存在!请重新输入!", vbExclamation + vbOKOnly, "友情提示"
                Text1.Text = ""
                Text2.Text = ""
                Text1.SetFocus
                gdbConn.Close
                End If
        End If
    
End Sub
    
Private Sub Command2_Click()
    Set gdbConn = Nothing
    Unload Me
End Sub
										

 2007-07-28 11:01
	    2007-07-28 11:01
   2007-07-28 11:55
	    2007-07-28 11:55