在参考了各种资料之后,实现了用户登录模块。主要难点集中在随机验证码的实现以及验证码在页面间的传递操作。具体实现代码如下:
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
- %>
为了使程序简单易懂,以上实现没考虑数据库的连接。,以及验证码的刷新问题。
转载于:https://blog.51cto.com/zbliangc/774392