JavaScript Password

This is how to make a password protected page using javascript. This may be better used under a programming topic, but it does relate to web design in that many web designers will want to protect a page with a password, possibly for members, etc.

How It's Done

This is quite a simple script, however, due to that, it is not very effective and I wouldn't recomend protecting anything important with it. Below is the script, I will then explain parts of it.


var password; (this defines a variable named password)

var pass1="GayGizmo"; (this creates the password that will be accepted. you can have more than one accepted, thus pass1, pass2, pass3, etc.)

password=prompt('Please enter your password',' '); (this prompts the viewer to enter a password. what he enters is now the value of the variable "password")

if (password==pass1)
alert('Password Correct! Click OK to enter!');
(if the password entered matches the one we set (GayGizmo), then it will alert that you have found the right password and it will take you to the page)

(this tells the script that if the password entered was something diff then it will take them to this site.)

And thats it for password protecting a page with javascript. Also, remember that this is not the safest way to protect a page and it can easily be cracked simply by looking at the pages source. Post anything else that has to do with password protecting or if you have some corrections to my script, etc.

"It's better to burn out, than to fade away."