注册 登录
编程论坛 ASP技术论坛

一个危险的粗心

笨笨林 发布于 2008-03-25 09:44, 750 次点击
我在写后台用户登陆的时候,就犯过一个很低级的错误,下面是代码。
程序代码:
dim username,userpass,yzm,sessionyzm

yzm=left(ReplaceBadChar(Trim(Request("yzm"))),4)
sessionyzm=left(ReplaceBadChar(Trim(Session("code"))),4)
Session("usercode")=""
if yzm<>sessionyzm then
response.write ("<script LANGUAGE='javascript'>alert('验证码错误!');history.go(-1);</script>")
resopnse.end
end if

username=left(Trim(Request("username")),16)
userpass=md5(left(Trim(Request("userpass")),20))
if not CheckUserBadChar(username) then
response.write ("<script LANGUAGE='javascript'>alert('对不起,您输入的用户名含有非法字符!');history.go(-1);</script>")
response.end
end if

if username="" then
response.write ("<script LANGUAGE='javascript'>alert('对不起,用户名不能为空!');history.go(-1);</script>")
response.end
end if

if yzm="" then
response.write ("<script LANGUAGE='javascript'>alert('非法的验证码或验证码为空!');history.go(-1);</script>")
resopnse.end
end if

当时调试的时候,没发现问题,可是后来自己一次不小心输错了验证码,居然正常登陆后台,以为自己看错了,再重复一次也一样,但是当用户名或密码也错的时候就提示验证码错误。用户名和密码正确时验证码不管错和对都一样。以为是接收到的验证码字符有其它字符,但是经过排除也还是一样。最后打算重写验证代码时终于发现了问题所在
if yzm<>sessionyzm then
response.write ("<script LANGUAGE='javascript'>alert('验证码错误!');history.go(-1);</script>")
resopnse.end
end if

后面那句resopnse.end应写成response.end
这样造成发现验证码错误时,服务器端继续执行,如果用户名密码没有错,就会
response.redirect ("index.asp")
如果有错,就会response.end
然后再出现验证码错误,所以调试的时候用户名和密码也是错的,验证码这里就被溜过去了。
5 回复
#2
wuchunyu1202008-03-25 10:17
谢谢分享。。
#3
longziyong2008-03-25 10:29
不仔细看,还真看不出来!
#4
永夜的极光2008-03-25 10:53
不知道LZ用什么编辑器写代码?
如果你用DW写的话,这种错误应该不会出现
#5
笨笨林2008-03-27 12:10
Notepad2
#6
gdk20062008-03-27 13:04
呵呵!这个应该是知道的,比如:如果你后面还有写入数据库信息的那就惨了。
1