![]() |
#2
wuchunyu1202008-03-25 10:17
|

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
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
response.write ("<script LANGUAGE='javascript'>alert('验证码错误!');history.go(-1);</script>")
resopnse.end
end if
后面那句resopnse.end应写成response.end
这样造成发现验证码错误时,服务器端继续执行,如果用户名密码没有错,就会
response.redirect ("index.asp")
如果有错,就会response.end
然后再出现验证码错误,所以调试的时候用户名和密码也是错的,验证码这里就被溜过去了。