Password Protection
The following is the JavaScript code to add a password to your page. You should note that this is not totally secure. You should not keep information such as credit card numbers or other sensitive information on the pages.
Fire up Notepad and copy the below code. Save the code as "password.txt". When you upload it to your server make sure to change the filename to "password.js".
If you can not change the file name when uploading, you must use a hex editor to save the file as 'password.js'. Click here to go to a site where you can download a hex editor.
<!--//
// Password Protection
//
// This code is free to be used as long as these
// credits are left intact and included with the script:
//
// Original code created by:
// S. Scott Brady, Copyright (C) 1998
// http://www.sbrady.com/
// webmaster at sbrady dot com
//
Hide from old browsers
var password = prompt("Enter your password","");
if (password == "hotsource") {
alert("Password accepted! Loading page...");
document.write("<p>This is where you put your html code.</p>");
document.write("<p>It is a little annoying having to put ");
document.write("all your code in the WRITE ");
document.write("tags, but it is free and doesn't require ");
document.write("a special server.</p>");
}
else {
alert("" +password+ " is an Invalid Password! Access denied...");
document.write("<p><b>You have entered an invalid password. ");
document.write("Access to the document is denied.</b></p>");
}
How to use the code:
In your HTML document, add the following markup.
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript" SRC="http://www.yourdomain.com/password.js">
</SCRIPT>
</BODY>
</HTML>
Notes:
- Change "hotsource" to the password of your choice.
- Change "http://www.yourdomain.com/" to the URL of the .js file.
- Put \r\n in the write tags to produce a break and \" to produce a quote.
- To ensure the code is copied correctly, please click here.
(the password is 'hotsource')
