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

login.asp:

 

 
  
  1. <
  2. FUNCTION GEN_KEY(digits) 
  3. dim char_array(80) 
  4. for i=0 to 9 
  5. char_array(i)=cstr(i) 
  6. next 
  7. for i=10 to 35 
  8. char_array(i)=chr(i+55) 
  9. next 
  10. for i=36 to 61 
  11. char_array(i)=chr(i+61) 
  12. next 
  13. randomize 
  14. do while len(output)<digits 
  15. num=char_array(int((62-0+1)*rnd+0)) 
  16. outputoutput=output&num 
  17. loop 
  18. gen_key=output 
  19.  
  20. end function 
  21. %> 
  22. <html> 
  23. <head></head> 
  24. <body> 
  25. <form name="form1" action="check.asp"> 
  26. 用户登录界面: 
  27. <BR> 
  28. 用户名:<INPUT TYPE=TEXTBOX NAME="TXTNAME"></input> 
  29. <BR> 
  30. 密码:<INPUT TYPE=TEXTBOX NAME="TXTPWD"></input> 
  31. <BR> 
  32. 验证码:<INPUT TYPE=TEXTBOX NAME="TXTYZM"> 
  33. </INPUT> 
  34. <
  35. session("verifycode")=gen_key(4) 
  36. response.write session("verifycode") 
  37. %> 
  38.  
  39. <BR> 
  40. <input type=submit value="登录" /> 
  41. <input type=reset value="重置" /> 
  42. </form> 
  43.  
  44. </body> 
  45. </html> 

check.asp:

 

 
  
  1. <
  2. dim user 
  3. dim pwd 
  4. dim yzm 
  5. user=trim(request("txtname")) 
  6. pwd=trim(request("txtpwd")) 
  7. yzm=trim(request("txtyzm")) 
  8.  
  9. if user="" or pwd="" then 
  10.     response.write "<script>alert('对不起,用户名和密码不能为空!');document.location.href='login.asp';</script>
  11.     response.end 
  12. else 
  13.  
  14.     if user="lc" then 
  15.         if pwd="1234" then 
  16.             if session("verifycode")=yzm then 
  17.                 response.redirect "http://www.baidu.com" 
  18.             else 
  19.                 response.write "验证码输入有误!" 
  20.             end if 
  21.         else 
  22.             response.write "密码输入有误!" 
  23.         end if 
  24.     else 
  25.         response.write "用户名不存在!" 
  26.     end if 
  27.  
  28. end if 
  29.  
  30.          
  31. %> 

为了使程序简单易懂,以上实现没考虑数据库的连接。,以及验证码的刷新问题。