A detailed tutorial on making a password protected HTML page with JavaScript.
First off, you need to create a folder to put your Java script Password Protect project. To create a folder, Right click>New>Folder. I decided to name my folder “js test”. You can name yours whatever you want to name it.
For this project, you will need to make two HTML pages. One will be used for your protected page, and the other will be used for the incorrect Password Page. I will not discuss how to create HTML pages in this tutorial. After you have your two HTML pages done, open up another notepad document. This will be our java script coding.
Type in the following code:
var wrong=”page1.HTML”;
This will tell the computer where to send you if your password you entered is wrong. So replace
page1.HTML with whatever the name of your incorrect password page is.
Next, type in:
var right=”page2.HTML”;
This part will tell the computer where to send you if your password is correct. So this time, replace page2.HTML with whatever your password protected page is.
Now type in the following:
var password=”pass”;
This tells the computer what your password is. Replace pass with your desired password.
Now to finish it all up, type in the commands:
var name = prompt(”Please type in the password”,”);
if (name == password) {location.href=right}
else {location.href=wrong}
Save the document with your desired name plus a .js at the end.
Also, don’t forget to add, under the tag of your password protected HTML page.
Tips and Cautions: Do not trust Java script as a great password protector. Someone can easily find your script and open it up and read your password. So if you want your page more protected, mark your script as hidden. This is meant for personal desktop computer purposes, not to secure a page on the Internet.












Leave Your Response