Javascript – Simple Password Protection
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | <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:
1 | var password = 'mypassword' ; // setup the password here |
Notice the redirect setup at:
1 2 3 | top.location.href= "correct.html" ; // password correct ... location.href= "incorrect.html" ; // password incorrect |