Topics:
» ASP
» HTML
» Stylesheets
» JavaScript
» PHP
» Flash
» More...

Site:
» Forum
» About

Password Protection

This will show you how to make a password page. Its not secure as anyone could go straight to the target page but it will still keep most visitors out. In you you put in your password and if it is correct you go the another page. If you are incorrect you go to a wrong password page. Take a look at the script:

<SCRIPT Language = "JavaScript">
function passwordOK(anystring) {
anystring = anystring.toUpperCase()

if (anystring == "GREEN" || anystring == "BLUE" || anystring
== "RED" || anystring == "YELLOW") {
/*Add more passwords if you'd like, but ALL PASSWORDS MUST BE IN CAPS!*/
alert('You got it right!')
alert('Now taking you to the hidden page.')
location="page2.htm"
//Change page2.htm to your hidden page
}


else {
alert ("Please enter the CORRECT password next time.")
location="wrongpage.htm"
/*substitute your own wrong page for wrongpage.htm*/
}
}
</SCRIPT>
<FORM>
<b>Password: </b>
<INPUT type="password" name='pass' Size = 20 onChange =
"passwordOK(this.value)">
</FORM>

As you can see the input box triggers the javascript function 'passwordOK.' Below the function name, in th nex paragragh and what to do if the password is correct. Below that is the alert if the password is incorrect. Have a play around with the script and see what you can do. The whole thing can be copied in the body tag of your page.