select count(*) from table where xingming = 'xingming' and password = 'password'
解决方案 »
- vb发生单击事件!
- 如何获取主流物流跟踪信息?
- 关于字符排列问题
- 书上MP3播发器的问题
- 打印问题
- 怎么通过MSComm控件与读卡器配合读出一张卡内的信息?谢谢
- 看看是什么原因?大家给分析一下!!!
- 在哪里可以找到水晶报表的设计器。
- 100分求解蓝屏问题(分数在windows2000下面的帖子里)----操作系统是 Windows2000,我的计算机在关闭/重启时有蓝屏,只有手动按下Power/Reset键才能关闭/重启。蓝屏显示:
- 又有关于ACTIVEX DLL的问题,挺有深度和实际实践意义的。
- VB中数据库查询的问题:)
- 有一个程序用了很多图片框,在32位色下,速度慢,内存占用多。请问如何强制窗口或者图片框在256或者16位色下运行?
我用ADODC连接数据库
应分配一个唯一的ID号+password
OK,就像学生数据库档案一样,用来验证的不是姓名而是由学校分配的学号,这个没有重复的吧。相信这是你程序里面的BUG
rs.open sql ,conn,1,1
if rs.reordcount>0 then
msgbox "正确!"
if rs.reordcount>1then
msgbox "多个用户有此名和密码,在注册时候要考虑唯一性的问题!" end if
end if
cretae proc 名
@用户 varchar(100),
@密码 varchar(100)
as
begin
if exists(select 1 from 表 where 用户列=@用户 and 密码=@密码)
return 1
else
return 0
end
我用的是ADODC连接数据库啊
adodc1.refresh
if adodc1.recordset!counts=0 then
msgbox "没有通过身份验证"
else
msgbox "通过身份验证"
end if
"select count(*) from table where xingming = '" & xingming & "' and password = '" & password & "'"这样的SQL语句进行判断,有漏洞。如果xingming是不为空的字符串"abc"
password如果输入abc' or '1'='1这时查询条件永远为真,则起不到身份验证的作用。
出现错误提示:FROM子句语语法错误
"select xingming,password from table where xingming = '" & xingming & "' and password = '" & password & "'"
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
天啊,我以前写的几个系统都是用的这个方法,怎么办?晕倒了
if cnn.execute(strsql).eof then
'无符合条件的记录
else
'有符合条件的记录
end if
strSql="select * from table where xingming = '" & xingming & "' and password = '" & password & "'"
我一般是这样判断的,不知道是不是可以避开你所说的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
你的方法可以避免身份验证的漏洞。但方法可以再简单一些(只是示意,没有检查语法和调试)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
这句提示有错!
多谢您对我代码的优化,以前我都不太注重代码的优化..看来以后我要多多的注意了,谢了!
str=select * from table where xingming = '" & xingming & "' and password = '" & password & "'"if adodc1.recordset.recordcount!=0 then
msgbox "用户不存在"
else
msgbox "用户存在"
end if