户登录时密码不能超过5次,应该如何统计用户密码输入错误的次数
想做一个登录页,提示用户登录时密码不能超过5次,应该如何统计用户密码输入错误的次数,定义了session(“num”)来统计,在判断用户名,密码错误时累计加1,但是切换用户登录错误时,依旧累加二不是从1开始累计。
代码如下:
global.asa
<Script language="VBScript" RUNAT="Server">
sub Application_OnStart
Application.lock
Application("whoson")=0
Application.unlock
End Sub
Sub Application_OnEnd
End Sub
Sub Session_OnStart
session("check_num")=0
End Sub
Sub Session_OnEnd
End Sub
</Script>
logincheck.asp
<!--#include file="connection.asp"-->
<body bgcolor="#E1F1E4"><%
id=trim(request.form("id"))
pw=trim(request.form("pw"))
safecode=trim(request.form("validatecode"))
session("id")=id
session("pw")=pw
conn.Open ConnStr
set rs=server.createobject("adodb.recordset")
if id="" or pw="" or safecode="" then
%>
<script language="VBScript">
alert("用户名、密码或验证码不能为空,请重新输入!")
window.location.href="login.asp"
</script>
<%
end if
If Trim(Request.form("validatecode"))=Empty Or Trim(Session("safeCode"))<>Trim(Request.form("validatecode")) Then %>
<script language="VBScript">
alert("验证码不正确,请重新输入!")
window.location.href="admin.asp"
</script>
<%response.end
end if
sql="select * from user where name='"&id&"' and password='"&pw&"'"
rs.open sql,conn,1,1
if not rs.eof and not rs.bof then
response.redirect "user_index.asp"
end if
else
session("check_num")=session("check_num")+1
if session("check_num")<=3 then
%>
<script language="VBScript">
alert("密码错误,您有五次机会!")
window.location.href="login.asp"
</script>
<%else%>
<script language="VBScript">
alert("密码错误,您已无法登陆!")
window.location.href="login.asp"
</script>
<%end if%>
<%end if%>
哪里错了吗?
或者还是有更好方法?