Design of ASP User Login module

Source: Internet
Author: User
Tags object exit end
Design of ASP User Login module

User logon verification script, chkpwd.asp

  1. <%
  2. ' ======= user logon verification script =======
  3. ' If the passed object has not been defined, it is defined as false, indicating that the validation is not passed
  4. If IsEmpty (Session ("passed")) Then
  5. Session ("passed") =false
  6. End If
  7. ' Session (' passed ') =false, indicating that validation has not yet been validated, starts reading the authentication information from the form
  8. If session ("passed") =false Then
  9. Username=request.form ("UserName")
  10. Userpwd=request.form ("Userpwd")
  11. If username= "" Then
  12. errmsg= "prompt: Please enter user name and password"
  13. Else
  14. ' =================== Connection Database =====================
  15. Set conn= Server.CreateObject ("ADODB.") Connection ")
  16. Conn.connectionstring= "Driver={sql Server}; server=192.168.1.3; Uid=sa; pwd=;D Atabase=zcmrs "
  17. Conn.Open
  18. ' =================== reads the user data from the table log =====================
  19. ' Define a Recordset object
  20. Set rs=server.createobject ("ADODB. Recordset ")
  21. ' Set the connectionstring of the Connection object
  22. Set Rs. Activeconnection=conn
  23. ' Set Cursor type
  24. Rs. Cursortype=3
  25. ' Open recordset
  26. Rs. Open "Select Username,password from Erpuser Where username= '" &UserName& ""
  27. ' =================== authentication ======================
  28. If Rs. EOF Then
  29. errmsg= "prompt: User does not exist or password is wrong"
  30. Else
  31. If Userpwd<>rs. Fields ("password") Then
  32. errmsg= "Hint: Login failed! "
  33. Else ' Login Successful
  34. Errmsg= ""
  35. Session ("passed") =true
  36. Session ("UserName") =rs. Fields ("username")
  37. ' Identify user rights session (' UserID ') =rs. Fields ("UserID")
  38. End If
  39. End If
  40. End If
  41. End If
  42. ' Login unsuccessful, then draw the login form
  43. If not session ("passed") =true Then
  44. %>
  45. <style type= "Text/css" >
  46. <!--
  47. . STYLE1 {font-size:12px;font-weight:bold;margin-left:120px;outline:double}
  48. -->
  49. </style>
  50. <style type= "Text/css" >
  51. <!--
  52. . STYLE2 {font-size:12px;font-weight:bold;outline:double;color: #FF3333}
  53. -->
  54. </style>
  55. <body leftmargin=0 topmargin=0 marginheight= "0" marginwidth= "0" bgcolor= "#000000" >
  56. <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 ">
  57. <div Id=denglu style= "Font-size:12px;font-weight:bold;background-color: #0099FF; text-align:center;height:40px;" ><br>erp System Login </div>
  58. <form action= "<%=request. ServerVariables ("Path_info")%> "method=" post "name=" MyForm "id=" MyForm ">
  59. <p class= "STYLE1" > Username: <input name= "UserName" type= "text" id= "UserName" size= "a" maxlength= ">"
  60. </p>
  61. <p class= "STYLE1" > Password: <input name= "userpwd" type= "password" id= "Userpwd" size= "a" maxlength= ">"
  62. </p>
  63. <p align= "center" class= "STYLE2" ><%=Errmsg%> </p>
  64. <p>
  65. <input type= "Submit" align= "Middle" name= "submit" value= "Login System" >
  66. <input name= "Rege" type= "button" align= "Middle" onclick= "location=" "Register.asp" id= Rege "" (Registered users) >
  67. </p>
  68. </form>
  69. </div>
  70. </body>
  71. <%
  72. ' <p class= ' STYLE1 > Verification Code: <input name= "Checkcode" type= "text" id= "Checkcode" size= "6" maxlength= "4" >
  73. "</p>
  74. Response. End
  75. End If
  76. %>

The page to be accessed erp.asp

    1. <!--#include file= "chkpwd.asp"-->
    2. <body>
    3. <div style= ' font-size:12px;font-weight:bold;border:1px solid #001;p adding:4px;background: #FFCCFF; margin-top:0; ' > Welcome to use the ERP query system, the current logged-in user is:
    4. <%
    5. If session ("passed") =true Then
    6. Response.Write (Session ("UserName"))
    7. End If
    8. %><a href= "logout.asp" > Exit system </a>
    9. </div>
    10. </body>

Each time you open erp.asp, the chkpwd.asp () is executed first, which effectively prevents unauthorized users from accessing the specified Web page.

logout.asp System exit

    1. <body>
    2. <%
    3. Session ("passed") =false
    4. Session ("UserName") = ""
    5. Response.Redirect ("index.asp")
    6. %>
    7. </body>

Submit a form with a picture

    1. <form name= "Form1" method= "Post" action= "" >
    2. <TD align= "right" ><input type= "image" method= "submit" name= "Submit" src= "Image/loginin.gif" width= "70" height= "alt=" "Submit" ></td>
    3. </form>


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.