Javascript – Simple Password Protection

<HTML>
<HEAD>
<TITLE>Login</TITLE>

<script language="JavaScript" type="text/javascript">
<!--- PASSWORD PROTECTION SCRIPT

function TheLogin() {

var password = 'mypassword'; // setup the password here

if (this.document.login.pass.value == password) {
  top.location.href="correct.html"; // password correct
}
else {
  alert("Password Incorrect");
  location.href="incorrect.html";   // password incorrect
  }
}
// End hiding --->
</script>

<style type="text/css">
BODY { COLOR: #0000FF; FONT: 12px verdana, arial, sans-serif; font-weight: normal }
</style>

</HEAD>

<BODY bgColor="#FFFFFF">

<br><br><br><br>

<center>
Enter your password:<br>
<form name="login" style="margin: 0px">
<INPUT TYPE="text" NAME="pass" size="17" onKeyDown="if(event.keyCode==13) event.keyCode=9;" style="width: 152px; margin: 5px;"><br>
<input type="button" value="Click to Login" style="width : 150px; margin: 3px" onClick="TheLogin(this.form)">
</form>
</center>

<br><br><br>

</BODY></HTML>

Super Easy!
Notice the password setup at:

var password = 'mypassword'; // setup the password here

Notice the redirect setup at:

top.location.href="correct.html"; // password correct
...
location.href="incorrect.html";   // password incorrect

My official WebSite >