ASP用户登录模块的设计

用户登录验证脚本,Chkpwd.asp

ASP/Visual Basic代码
  1. <%    
  2. '=======用户登录验证脚本=======    
  3. '如果尚未定义Passed对象,则将其定义为false,表示没有通过验证    
  4. If IsEmpty(Session("Passed")) Then    
  5. Session("Passed")=false    
  6. End If    
  7.   
  8. 'Session("Passed")=False,表示尚未通过验证,则开始读取从表单传来的验证信息    
  9. If Session("Passed")=False Then    
  10. UserName=Request.Form("UserName")    
  11. UserPwd=Request.Form("UserPwd")    
  12.   
  13. If UserName="" Then    
  14. Errmsg="提示:请输入用户名和密码"    
  15. Else    
  16. '===================连接数据库=====================    
  17. Set Conn= Server.CreateObject("ADODB.Connection")    
  18. Conn.Connectionstring= "Driver={SQL Server};Server=192.168.1.3;UID=sa;PWD=;Database=zcmrs"    
  19. Conn.open    
  20. '===================从表log中读取用户数据=====================    
  21. '定义RecordSet对象    
  22. Set rs=Server.CreateObject("ADODB.Recordset")    
  23. '设置Connection对象的ConnectionString    
  24. Set rs.ActiveConnection=Conn    
  25. '设置游标类型    
  26. rs.CursorType=3    
  27. '打开记录集    
  28. rs.Open "Select username,password from erpuser Where username='"&UserName"'"    
  29. '===================身份验证======================    
  30. If rs.EOF Then    
  31. Errmsg="提示:用户不存在或密码错误"    
  32. Else    
  33. If UserPwd<>rs.Fields("password"Then    
  34. Errmsg="提示:登录失败!密码错误?"    
  35. Else '登录成功    
  36. Errmsg=""    
  37. Session("Passed")=True    
  38. Session("UserName")=rs.Fields("username")    
  39. '标识用户权限 Session("UserID")=rs.Fields("UserID")    
  40. End If    
  41. End If    
  42. End If    
  43. End If    
  44. '经过登录不成功,则画出登录表单    
  45. If Not Session("Passed")=True Then    
  46. %>    
  47.   
  48. <html>    
  49. <head><title>无标题文档</title>    
  50. <style type="text/css">    
  51. <!--    
  52. .STYLE1 {font-size: 12px;font-weight:bold;margin-left:120px;outline:double}    
  53. -->    
  54. </style>    
  55. <style type="text/css">    
  56. <!--    
  57. .STYLE2 {font-size: 12px;font-weight:bold;outline:double;color:#FF3333}    
  58. -->    
  59. </style>    
  60. </head>    
  61.   
  62. <body leftmargin=0 topmargin=0 marginheight="0" marginwidth="0" bgcolor="#000000">    
  63. <div id=parent style="height:300;width:450;border-style:solid;border-color:#FFFFFF;margin-top:80px;margin-left:25%;margin-right:25%;background-color:#FFFFFF">    
  64.   
  65. <div id=denglu style="font-size:12px;font-weight:bold;background-color:#0099FF;text-align:center;height:40px;"><br>ERP系统登录</div>    
  66. <form action="<%=request.ServerVariables("path_info")%>" method="post" name="MyForm" id="MyForm">    
  67. <p class="STYLE1">用户名:<input name="UserName" type="text" id="UserName" size="18" maxlength="20">    
  68. </p>    
  69. <p class="STYLE1">密 码:<input name="UserPwd" type="password" id="UserPwd" size="18" maxlength="20">    
  70. </p>    
  71. <p align="center" class="STYLE2"><%=Errmsg%> </p>    
  72. <p>     
  73. <input type="submit" align="middle" name="Submit" value="登录系统">     
  74. <input name="rege" type="button" align="middle" onClick="location='register.asp'" id="rege" value="注册用户">    
  75. </p>    
  76. </form>    
  77. </div>    
  78.   
  79. </body>    
  80.   
  81. </html>    
  82. <%    
  83. '<p class="STYLE1">验证码:<input name="CheckCode" type="text" id="CheckCode" size="6" maxlength="4">    
  84. '<IMG style="MARGIN-RIGHT: 40px" alt="" src="common/getcode.asp"></p>    
  85. response.End    
  86. End If    
  87. %>  

要访问的页面erp.asp

ASP/Visual Basic代码
  1. <!--#include file="chkpwd.asp"-->    
  2. <body>    
  3. <div style='font-size:12px;font-weight:bold;border:1px solid #001;padding:4px;background:#FFCCFF;margin-top:0;'>欢迎使用ERP查询系统,当前登录用户为:    
  4. <%    
  5. If Session("Passed")=True Then    
  6. Response.Write(Session("UserName"))    
  7. End If    
  8. %><a href="logout.asp">退出系统</a>    
  9. </div>    
  10. </body>  

以上每次打开erp.asp的时候,都首先执行Chkpwd.asp(),这样可以有效防止未授权用户访问指定网页.

logout.asp系统退出

ASP/Visual Basic代码
  1. <body>    
  2. <%    
  3. Session("Passed")=false    
  4. Session("UserName")=""    
  5. Response.Redirect("index.asp")    
  6. %>    
  7. </body>  

使用图片提交表单

XML/HTML代码
  1. <form name="form1" method="post" action="">    
  2.   
  3. <td align="right"><input type="image" method="submit" name="submit" src="image/loginin.gif" width="70" height="21" alt="submit"></td>    
  4.   
  5. </form>  

 



文章来自: 网络原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
相关日志:
评论: 0 | 引用: 0 | 查看次数: 601
发表评论
昵 称: 注册帐号 密码: 游客直接输入昵称不需要密码
内 容:
验证码: 验证码