After a brief search for examples of password protection code for a page, I found that my preferred solution was actually a combination of features by others. This script is a modified version of samples which offers a single password line of code to be installed into any page for protection.
Here is an easy way to provide password protection to any page. Save the following script into a file called "password_protect.asp". Put this page into the root of the application. Change the password in the file to the password of choice. Finally place this line of code into any page that requires protection.
'----------------------------------------------------- 'Perform check to see if password is submitted '-----------------------------------------------------
'strPW1 <> "" strPW1 = Request("MyPWD") if strPW1 <> "" then Response.Cookies("MyPWD") = strPW1 end if
'----------------------------------------------------- 'Perform check to see if password is correct '-----------------------------------------------------
'strPW2 <> MyPWD strPW2 = Request.Cookies("MyPWD") If strPW2 <> MyPWD Then Call PWDScreen() End if
</head> <body bgcolor="navy" text="gold"> <div align="center"> <form action="<%=strScriptName%>" method="POST"> <h2>This page is access controlled.<BR>Please enter the password key<br></h2> <input type="password" name="MyPWD" size="10"><br><br> <input type="submit" value="Submit"> </form> </div> </body> </html>
<% response.end End sub %>
That's it. Name this page "Password_protect.asp". Put this page into the root of the application and put the following line of code into the page that needs protection.