您的位置:首页 > 编程语言 > ASP

asp带验证码的用户登录及校验代码实现

2012-02-07 21:42 731 查看
在参考了各种资料之后,实现了用户登录模块。主要难点集中在随机验证码的实现以及验证码在页面间的传递操作。具体实现代码如下:

login.asp:

<%
FUNCTION GEN_KEY(digits)
dim char_array(80)
for i=0 to 9
char_array(i)=cstr(i)
next
for i=10 to 35
char_array(i)=chr(i+55)
next
for i=36 to 61
char_array(i)=chr(i+61)
next
randomize
do while len(output)<digits
num=char_array(int((62-0+1)*rnd+0))
outputoutput=output&num
loop
gen_key=output

end function
%>
<html>
<head></head>
<body>
<form name="form1" action="check.asp">
用户登录界面:
<BR>
用户名:<INPUT TYPE=TEXTBOX NAME="TXTNAME"></input>
<BR>
密码:<INPUT TYPE=TEXTBOX NAME="TXTPWD"></input>
<BR>
验证码:<INPUT TYPE=TEXTBOX NAME="TXTYZM">
</INPUT>
<%
session("verifycode")=gen_key(4)
response.write session("verifycode")
%>

<BR>
<input type=submit value="登录" />
<input type=reset value="重置" />
</form>

</body>
</html>

check.asp:

<%
dim user
dim pwd
dim yzm
user=trim(request("txtname"))
pwd=trim(request("txtpwd"))
yzm=trim(request("txtyzm"))

if user="" or pwd="" then
response.write "<script>alert('对不起,用户名和密码不能为空!');document.location.href='login.asp';</script>"
response.end
else

if user="lc" then
if pwd="1234" then
if session("verifycode")=yzm then
response.redirect "http://www.baidu.com"
else
response.write "验证码输入有误!"
end if
else
response.write "密码输入有误!"
end if
else
response.write "用户名不存在!"
end if

end if

%>

为了使程序简单易懂,以上实现没考虑数据库的连接。,以及验证码的刷新问题。
本文出自 “求学路” 博客,请务必保留此出处http://zbliangc.blog.51cto.com/655801/774392
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: