JavaScript: Password Protected Content with Redirect Page
Jack Donnell,
[email protected]
This is super simple. DO NOT RELY ON IT FOR TOTAL SECURITY!!!
The first version, I used an external .js file to create content. JavaScript: Deliver Password Protected Content
This Version a whole lot easier! It you to quickly paste a small code snippet into
your exiting pages.
I got the idea from http://www.felgall.com/javatip4.htm !!!
I just used the prompt snippet and put it into the <HEAD></HEAD>
part of the page to protect.
Try TopSecret.htm - Password is SuperSecret
<HEAD>
<Title> My Page to be Protected </Title>
<script type="text/javascript">
var pw =prompt('Please Enter a Password to View Protected Content: ','');
if (pw != 'XYZ') top.location = 'index.html';</script>
</HEAD>
The section (pw != 'XYZ') contains the Case sensitive password.
The != ( means does not equal) any other value entered into the
prompt gets redirected to the nope.htm page.
If the password does not match case or is invalid the material
on the page is secured.
This is poor man's simple security. You want to use something
robust for sensitive information. This will keep most out, but
probably not the ones you really wanted to stay away. You want
to add another script to protect the source of your files, too.
Another Tip:
Turn the the script into a js external JavaScript file and add
a cookie. You could have a login page that writes a user cookie
that your script would check for. If expired or missing, then the
script would be evolked again. The external script would simplify
admin for passwords if you need to add or change.
Thanks Carole for the Question !