asp帶驗證碼的用戶登錄及校驗代碼實現

 在參考了各種資料之後,實現了用戶登錄模塊。主要難點集中在隨機驗證碼的實現以及驗證碼在頁面間的傳遞操作。具體實現代碼如下:

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. %> 

爲了使程序簡單易懂,以上實現沒考慮數據庫的連接。,以及驗證碼的刷新問題。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章