Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 1.40 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ASP password protect improvement
  2. <%
  3.  
  4. needAuthentication = True
  5.  
  6. If Request.Form.Count > 0 Then
  7.     If Request.Form("username") <> "jon" Or Request.Form("password") <> "secret" Then
  8.         ' Redirect to another URI
  9.         Response.Redirect("/")
  10.         Response.End
  11.     End If
  12.     needAuthentication = False
  13. End If
  14.  
  15. %>
  16. <html>
  17. <body>
  18. <%
  19.  
  20. If needAuthentication Then
  21.  
  22. %>
  23. <form method="post" action="thenameofthepage.asp">
  24.   <div>Username: <input type="text" name="username" /></div>
  25.   <div>Password: <input type="text" name="password" /></div>
  26.   <div><input type="submit" value="Submit" /></div>
  27. </form>
  28. <%
  29.  
  30. Else
  31.  
  32. %>
  33. <p>Page content here</p>
  34. <%
  35.  
  36. End If
  37.  
  38. %>
  39. </body>
  40. </html>
  41.        
  42. <%
  43. needAuthentication = True
  44. authenticationFailed = False
  45.  
  46. If Request.Form.Count > 0 Then
  47.     If Request.Form("password") <> "secret" Then
  48.         authenticationFailed = True
  49.     End If
  50.     needAuthentication = False
  51. End If
  52.  
  53. %>
  54.  
  55.  
  56. <html>
  57. <body>
  58.  
  59. <%
  60. If needAuthentication Then
  61.  
  62. %>
  63.  
  64. <form method="post" action="passwordtest.asp">
  65.   <div>Password: <input type="text" name="password" /></div>
  66.   <div><input type="submit" value="Submit" /></div>
  67. </form>
  68.  
  69. <%
  70. Else
  71.  
  72. %>
  73.  
  74. <p>Page content here</p>
  75.  
  76. <%
  77. End If
  78.  
  79. %>
  80.  
  81. <%
  82. If authenticationFailed Then
  83.  
  84. %>
  85.  
  86. <script type="text/javascript">
  87.   alert("Invalid login");
  88. </script>
  89.  
  90. <%
  91. End If
  92. %>
  93.  
  94. </body>
  95. </html>
  96.        
  97. <%
  98.  
  99. If authenticationFailed Then
  100.  
  101. %>
  102. <script type="text/javascript">
  103.   alert("Invalid login");
  104. </script>
  105. <%