Site hosted by Angelfire.com: Build your free website today!

My Favorite Links

Date/Time
9/21/03
5:00 P.M Mouse over to see time 5:00 P.M

Free JavaScripts provided
by The JavaScript Source

Search this site or the web powered by FreeFind

Site search Web search

Google
WWW YOUR DOMAIN NAME

Card Type:
Credit Card Number:
Expiration Date (MM/YY):

If you have been through the previous tutorials, most of the code will make sense to you. Let's get to the details of what is going on with this thing: var password; This creates a variable named "password". var pass1="cool"; This creates a password that will be accepted by the script. We name it pass1 in case we would like to have more than one acceptable password. ( ie pass2, pass3 etc. ). password=prompt('Please enter your password to view this page!'1221,' '); This is what creates the prompt for the user to enter a password. Whatever the user enters in the prompt will be the value of the variable "password". If you have not seen prompts before, go to the prompts tutorial for more info. if (password==pass1) alert('Password Correct! Click OK to enter!'); This is where we verify the password. The variable "password" is what the user just typed into the prompt. The variable "pass1" is the only password we will accept. If they are the same, we send them an alert that the password was OK and they can continue. If you haven't seen if/else statements yet, go to the if/else page. For more on alerts, see the alerts page. else { window.location="http://www.pageresource.com/jscript/jpass.htm"; } This is what happens when they type in an incorrect password. We send them to a page of our choice. In IE4, it looks like nothing happened, it just reloads this page. In NS3 and 4 you will probably see the protected page for a quarter of a second. I said it wasn't the most secure script out there, so I would recommend the links at the end of the tutorial so you can get a more secure script. I chose to send it back to this page (jpass.htm), but you can type any url here you want. Maybe you could use something like: window.location="http://www.barbie.com"; Make them cringe a little....... All that's left after that is to link to the protected page from another page, like my link above to the example. No problem. Now, if you want more than one acceptable password, you can make a couple of modifications and you will have it. First, add more variables for the accepted passwords. If you want three good passwords, declare three variables. Since I had one named "pass1" already, I will just use "pass2" and "pass3": var pass1="cool"; var pass2="awesome"; var pass3="geekazoid"; Next, you will need to change your "if" statement to include the other two passwords. This is done with the || (or) operator: if (password==pass1 || password==pass2 || password==pass3) alert('Password Correct! Click OK to enter!'); This means that if the user typed in the correct value for "pass1" OR "pass2" OR "pass3", the password is correct and they can view the page. Here is how the full code would look for this: var password;1221 var pass1="cool"; var pass2="awesome"; var pass3="geekazoid"; password=prompt('Please enter your password to view this page!'1221,' '); if (password==pass1 || password==pass2 || password==pass3) alert('Password Correct!1221 Click OK to enter!'); else { window.location="http://www.pageresource.com/jscript/jpass.htm"; } If you want to see this in action, click the link for this example below. Enter one of the three correct passwords (cool, awesome, or geekazoid) and you will see the next page! Multiple Password Example So, why is it easy to hack the script? One way is for the viewer to disable javascript. Not only will they get to the page this way, they can also view the source code to see the passwords and use them later. Thus, if you are protecting something important, you should use something more secure. You can find some more secure password javascripts at The JavaScript Source. You can also look for a CGI password script at The CGI Resource Index. Well, that was OK, but if you go to the next section you will see a slightly better version of this same script. So, go on to Password Protection 2!


I've been alive for...

Free JavaScripts provided
by The JavaScript Source

Members-Only Area!
Username:
Password:
Example Page

Subscribe to my newsletter!

>

Email address:

1 2
3 Altavista

My Favorite Site for Home Pages

Dogpile. Unleash the power of meta-search!
Search Engine Watch: Tips About Internet Search Engines & Search ...
Search
mamma
[ MetaCrawler® ]
Search
Search Engine Colossus
Beaucoup! 2,000+ Search Engines, Indices and Directories
W3 Search Engines XML
Search Engines Worldwide (global & local search engines
AllSearchEngines.com - search engine index, search engine ...
SearchEngines.com - search engine rankings and search engine
Search Engine Showdown: The Users' Guide to Web Searching
Search Engine Submission Tips
- 37.com - 37 SEARCH ENGINES ! - www.37.com
Best Search Engines Quick Guide
A Helpful Guide to Search Engines, Top Page
Kansas City Public Library - Search the Internet
A collection of (mainly) special search engines
RootsWeb: Database Index
Virtual Search Engines - 1,000 Specialized Search Engines within ...
Freeality Internet Search Engines
Meta-Search Engines
MSN Search -- More Useful Everyday