在文本框的change事件中判断输入的密码是否与数据库中的一致。不过,我觉得你最好还是设置一个按钮,在按钮的click事件中进行判断的好。因为在密码被一位一位的输入到文本框的过程中进行判断的话,在没输入完全的时候肯定都提示密码是错的,这样不合理

解决方案 »

  1.   

    有E-MAIL吗?我可以发一个源代码给你!
      

  2.   


    [email protected]
    谢谢了
      

  3.   

    看我的源程序吧:
    创建一个数据库dbmain.mdb,内建一个表UserInfo,其中有两个字段:
    UserName、PassWord
    新建一个工程(废话!)
    新建一个窗体
    属性:
    name=frmMain
    caption="登陆"
    在窗体中加入两个文本框:
    txtUserName
    属性:
       text=""
    txtPassWord
    属性:
       text=""
       passwordchar="*"
    两个命令按钮:
    cmdOK
    属性:
       caption="确定"
       default=true
    cmdCancel
    属性:
       caption="取消"
       cancel=true
    一个DATA控件
    dtMain
    将其和前面的数据库连接
    以下是代码:Public pCheckOK As BoolenPrivate Sub Form_Load()
    pCheckOK=false
    End SubPrivate Sub cmdOK_Click()
    If txtUserName="" Or txtPassWord="" Then
        Msgbox "请输入完整的信息!!!"
        Exit Sub
    End If
    dtMain.Index="UserName"
    dtMain.Seek = ,txtUserName
    If dtMain.Founded Then
        If dtMain!Password=txtPassWord Then
            pCheckOK=True
            Me.Hide
        Else
            Msgbox "密码错误!!!"
            txtPassWord.SelStart=0
            txtPassWord.SelLength=Len(txtPassWord)
            txtPassWord.SetFocus
            pCheckOK=false
            Exit Sub
        End If
    Else
        Msgbox "无此用户!!!"
        txtUserName.SelStart=0
        txtUserName.SelLength=len(txtUserName)
        txtUserName.SetFocus
        pCheckOK=false
    End If
    End SubPrivate Sub cmdCancel_Click()
    pCheckOK=flase
    Me.Hide
    End Sub好了!
    就这样了!
      

  4.   

    Option Explicit
    Dim db As Database
    Dim rs As RecordsetPublic LoginSucceeded As BooleanPrivate Sub cmdCancel_Click()
        '设置全局变量为 false
        '不提示失败的登录
        LoginSucceeded = False
        Me.Hide
    End SubPrivate Sub cmdOK_Click()
    Set db = OpenDatabase(App.Path & "\password.mdb")
    Set rs = db.OpenRecordset("select * from UserName where 用户名='" & txtUserName & "'")
    If rs.RecordCount > 0 Then
        '检查正确的密码
        If txtPassword = rs.Fields("密码") Then
            '将代码放在这里传递
            '成功到 calling 函数
            '设置全局变量时最容易的
            Form1.Visible = True
            LoginSucceeded = True
            Me.Hide
        Else
            MsgBox "无效的密码,请重试!", , "登录"
            txtPassword.SetFocus
            SendKeys "{Home}+{End}"
        End If
    Else
        MsgBox "数据库错误!"
        txtPassword.SetFocus
        SendKeys "{Home}+{End}"
    End If
    End Sub
      

  5.   

    这是我自己做的一个,已经在win2000+vb6下通过,不过是适合我自己的系统,不知道适合不适合你. 我用的是vb6+sql server7.0
    --------------------------
    Option Explicit
    Public Con As ADODB.Connection
    Public ConString As String
    Dim i As Integer
    Dim RS As ADODB.RecordsetPrivate Sub cmdCancel_Click()
        '设置全局变量为 false
        '不提示失败的登录
       Unload Me
       MDIxiaoqu.Enabled = True
    End SubPrivate Sub cmdOK_Click()Dim Con As ADODB.Connection
    Dim RS As ADODB.Recordset
    Set Con = New ADODB.Connection '新建一个连接
    ConString = "ODBC;DRIVER= {SQL SERVER};UID=SA;PWD=;SERVER=nick;DSN=Xiaoqu;DATABASE=Xiaoqu;" '设定连接字符串
    Con.Open ConStringSet RS = New ADODB.Recordset
    If txtUserName.Text = "" Or txtPassword = "" Then
       MsgBox "请输入完整的信息", , "提示"
       txtUserName.SetFocus
       Exit Sub
       
    Else
    RS.Open "select * from Users where username = ('" & Trim(txtUserName.Text) & "') and password =('" & Trim(txtPassword.Text) & "')", Con
    If Not (RS.EOF And RS.BOF) Then
       
       
       If txtUserName.Text <> "admin" Then
          MDIxiaoqu.mnunew.Enabled = False
          MDIxiaoqu.mnubackup.Enabled = False
          MDIxiaoqu.mnuhuifu.Enabled = False
          MDIxiaoqu.Picture9.Enabled = False
          MDIxiaoqu.Picture11.Enabled = False
          MDIxiaoqu.Picture12.Enabled = False
          MDIxiaoqu.Label7.Enabled = False
          MDIxiaoqu.Label9.Enabled = False
          MDIxiaoqu.Label10.Enabled = False
       Else
          MDIxiaoqu.mnunew.Enabled = True
          MDIxiaoqu.mnubackup.Enabled = True
          MDIxiaoqu.mnuhuifu.Enabled = True
          MDIxiaoqu.Picture9.Enabled = True
          MDIxiaoqu.Picture11.Enabled = True
          MDIxiaoqu.Picture12.Enabled = True
          MDIxiaoqu.Label7.Enabled = True
          MDIxiaoqu.Label9.Enabled = True
          MDIxiaoqu.Label10.Enabled = True
       End If
       MDIxiaoqu.Show
       MDIxiaoqu.Enabled = True
       Unload Me
    Else
      
       MsgBox "系统中没有这个用户或者你的密码输入有误!", , "请重新输入"
       txtUserName.Text = ""
       txtPassword.Text = ""
       txtUserName.SetFocus
       Exit Sub
    End If
    End IfEnd Sub