Copyright © All rights reserved. Made By RichoSoft.  Terms of use | Privacy policy
Welcome.All Resources.Page Counters.Tips & Tricks Menu.Contact us.My Account.Site Map.
Welcome.All Resources.Page Counters.Tips & Tricks Menu.Contact us.My Account.Site Map.
Password Protecting Web Pages with ASP - Sample Code
<%@ LANGUAGE="VBSCRIPT" %>
<html>
<!--- (c) 2009 - RS Web Resources - RichoSoft --->
<!--- You may modify this code to your own requirements --->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>RS Web Resources - Password Page Demo</title>
</head>

<body>
<%
' *** Check to See if Form on this page has been submitted - If it has not then draw the page and stop at the first Response.End ***
If Request.Form("ChkPass") <> "Y" then
%>
<!--- Draw the Form --->
 <div style="position: absolute; top: 11; left: 32; width: 236; height: 104">
 <form method="POST" action="this_page_name.asp">
<!--- Target for the Form Submission is this same page --->  
     <p align="center">
     <font face="Arial" size="2">Enter the password to view this page
       <input type="password" name="fPassword" size="20">
     </font>
    <p align="center"><input type="submit" value="Submit" name="B1"></p>
<!--- When the form is submitted a hidden field ChkPass is included so that the code can see if the Form has been submitted -->
<!--- or tell that this is the first time the page has been viewed --->       
      <input type="hidden" name="ChkPass" value="Y">
 </form>
 </div>
<%
Response.End
End If
' *** Check to see if correct password has been entered - It doesn't matter that the password is on the page as the page ***
' *** will be generated at the Server so the VB Code will not be visible to the user even if they View the Page Source   ***

If Request.Form("fPassword") <> "PASSWORD" then
Response.Write "<span style='position: absolute; left: 15; top: 6; width: 300;'>"
Response.Write "<font face='arial' size='2'><hr><b><p align='center'>The password you entered was incorrect.<BR>Please Click <a href='this_page_name.asp'>here</a> to try again.</p></b><hr>"

' *** If the password was incorrect then display the message above and stop displaying any more of the page ***

Response.End

End if
%>
<!--- If the Password was correct it will allow the Rest of the Page Code below to be displayed --->

<p><span style="position: absolute; left: 15; top: 6"><img border="0" src="images/rswcut.png" width="276" height="242"></span></p>
<div style="position: absolute; top: 271; left: 11; width: 717; height: 60">
 <b><font size="3" face="Arial">The Password you entered was correct.
    </font></b>
    &nbsp;&nbsp;&nbsp;&nbsp;
    <font size="3" face="Arial"><b>So the rest of your page code will be displayed</b>
     </font>
 <b><font size="3" face="Arial">.
    </font></b>
</div>
<div style="position: absolute; top: 32; left: 320; width: 372; height: 29">
 <b><font face="Arial" size="5">Password Protected Page Demo
    </font></b>
   <p align="center"><b><font face="Arial" size="5">Using ASP 3.0
    </font></b>  
</div>
</body>
</html>
In this example we have added some positioning code just to make the results a little prettier and some comments to guide you through the code. This is the sample page this_page_name.asp.