select count(*) from table where xingming = 'xingming' and password = 'password'

解决方案 »

  1.   

    能不能给个完整的语句啊,姓名和密码正确后给出提示
    我用ADODC连接数据库
      

  2.   

    我想这是你程序的BUG吧,当客户申请时就不充许有重复的用户名,银行帐号?学生数据库ID号,如果真有重复的用户名,那么该字段不能被程序拿来验证用!
    应分配一个唯一的ID号+password
    OK,就像学生数据库档案一样,用来验证的不是姓名而是由学校分配的学号,这个没有重复的吧。相信这是你程序里面的BUG
      

  3.   

    sql="select * from table where xingming = '" & xingming &"' and password = '" & password &"'"
    rs.open sql ,conn,1,1
    if rs.reordcount>0 then
    msgbox  "正确!"
         if rs.reordcount>1then
           msgbox "多个用户有此名和密码,在注册时候要考虑唯一性的问题!"    end if
    end if
      

  4.   

    用过程:
    cretae proc 名
    @用户 varchar(100),
    @密码 varchar(100)
    as
    begin
      if exists(select 1 from 表 where 用户列=@用户 and 密码=@密码)
        return 1
      else
        return 0
    end
      

  5.   

    上面的代码都不行啊
    我用的是ADODC连接数据库啊
      

  6.   

    adodc1.recordsource="select count(*) as Counts from table1 where 姓名+密码 = '" & text1.text & text2.text & "'"
    adodc1.refresh
    if adodc1.recordset!counts=0 then
       msgbox "没有通过身份验证"
    else
       msgbox "通过身份验证"
    end if
      

  7.   

    建议不要使用
    "select count(*) from table where xingming = '" & xingming & "' and password = '" & password & "'"这样的SQL语句进行判断,有漏洞。如果xingming是不为空的字符串"abc"
    password如果输入abc' or '1'='1这时查询条件永远为真,则起不到身份验证的作用。
      

  8.   

    回Cooly(烦) ( )  
    出现错误提示:FROM子句语语法错误
      

  9.   

    不能根据有没有记录来判断,一定要取出返回的记录,比较姓名和密码是否相符。
    "select xingming,password from table where xingming = '" & xingming & "' and password = '" & password & "'"
      

  10.   

    简单的办法(前提是用户名唯一)
    adodc1.recordsource="select password from table1 where xingming = '" & xingming & "'"adodc1.refreshif adodc1.recordset.recordcount=1 then
       msgbox "用户存在"
       if trim(adodc1.recordset!password)=trim(password) then
          msgbox "通过身份验证"
       else
          msgbox "身份验证失败"
       end if
    end if
      

  11.   

    "select count(*) from table where xingming = '" & xingming & "' and password = '" & password & "'"
    天啊,我以前写的几个系统都是用的这个方法,怎么办?晕倒了
      

  12.   

    strSql="select count(*) from table where xingming = '" & xingming & "' and password = '" & password & "'"
    if cnn.execute(strsql).eof then
       '无符合条件的记录
    else
       '有符合条件的记录
    end if
      

  13.   

    更正:
    strSql="select * from table where xingming = '" & xingming & "' and password = '" & password & "'"
      

  14.   

    请教 Cooly(烦) :
    我一般是这样判断的,不知道是不是可以避开你所说的BUG呢?还有,请你给出一个能说明BUG的例子好吗?我自己试了一下,没有出现像你所说的BUG呀?..
    Private Sub cmdOk_Click()
        Dim strUserPass As String
        '判断用户是否已经输入用户名和密码
        golUsername = Trim(txtName.Text)
        strUserPass = Trim(txtPass.Text)
        If golUsername = "" Then
            MsgBox "请输入用户名", vbExclamation, "登录提示"
            txtName.SetFocus
            Exit Sub
        End If
        If strUserPass = "" Then
            MsgBox "请输入密码", vbExclamation, "登录提示"
            txtPass.SetFocus
            Exit Sub
        End If
        '判断用户登录信息是否正确
        sRs.Open "select * from TAB_User where 用户名='" & golUsername & "'", sCon, adOpenStatic, adLockOptimistic
        If sRs.EOF Then
            MsgBox "没有此用户", vbCritical, "登录错误"
            txtName.SelStart = 0
            txtName.SelLength = Len(txtName.Text)
            txtName.SetFocus
            sRs.Close
            Exit Sub
        End If
        sRs.Close
        sRs.Open "select * from TAB_User where 用户名='" & golUsername & "' and 用户密码='" & strUserPass & "'", sCon, adOpenStatic, adLockOptimistic
        If sRs.EOF Then
            MsgBox "密码错误", vbCritical, "登录错误"
            txtPass.SelStart = 0
            txtPass.SelLength = Len(txtPass.Text)
            txtPass.SetFocus
            sRs.Close
            Exit Sub
        End If
        sRs.Close
        ExecuteCommand "update TAB_user set 最近登录时间=#" & Now & "# where 用户名='" & golUsername & "'"
        MDIFormMain.Show
        Unload Me
    End Sub
      

  15.   

    TO sinom(毛毛):
    你的方法可以避免身份验证的漏洞。但方法可以再简单一些(只是示意,没有检查语法和调试)Private Sub cmdOk_Click()
        Dim strUserPass As String
        '判断用户是否已经输入用户名和密码
        golUsername = Trim(txtName.Text)
        strUserPass = Trim(txtPass.Text)
        If golUsername = "" Then
            MsgBox "请输入用户名", vbExclamation, "登录提示"
            txtName.SetFocus
            Exit Sub
        End If
        If strUserPass = "" Then
            MsgBox "请输入密码", vbExclamation, "登录提示"
            txtPass.SetFocus
            Exit Sub
        End If
        '判断用户登录信息是否正确
        sRs.Open "select * from TAB_User where 用户名='" & golUsername & "'", sCon, adOpenStatic, adLockOptimistic
        If sRs.EOF Then
            MsgBox "没有此用户", vbCritical, "登录错误"
            txtName.SelStart = 0
            txtName.SelLength = Len(txtName.Text)
            txtName.SetFocus
            sRs.Close
            Exit Sub
        Else
            if trim(sRs("用户密码"))<>txtPass.Text then
               MsgBox "密码错误", vbCritical, "登录错误"
               txtPass.SelStart = 0
               txtPass.SelLength = Len(txtPass.Text)
               txtPass.SetFocus
               sRs.Close
               Exit Sub
            else
               ExecuteCommand "update TAB_user set 最近登录时间=#" & Now & "# where 用户名='" & golUsername & "'"
               MDIFormMain.Show
               Unload Me
            end if
        End If
    End Sub
      

  16.   

    if cnn.execute(strsql).eof then
    这句提示有错!
      

  17.   

    To Cooly(烦):
    多谢您对我代码的优化,以前我都不太注重代码的优化..看来以后我要多多的注意了,谢了!
      

  18.   

    adodc1.recordsource="select password from table1 where xingming = '" & xingming & "'"
    str=select * from table where xingming = '" & xingming & "' and password = '" & password & "'"if adodc1.recordset.recordcount!=0 then
       msgbox "用户不存在"
    else 
       msgbox "用户存在"
    end if