Password Protection

What this script does:
This script requires the user to enter a password in order to gain access to a certain page in your website. After the specified amount of retries (the default is 3), the script will deny them access to the page. At the moment this script can only protect a certain page, not an entire sub-folder.


1) Create the password that you will like to use. Your password must be between 3 and 25 characters. As an example I willl use the password 'apple'.

Note: The password you create will need to be the same as the name of the page you are protecting. Since you will be linking to a page named password.html later in the tutorial, be sure not to use the word 'password' as the password for your protected page.

2) Click here to create your password.

Once you entered your password, it promted you to:

a) Write down the number that was generated.

b) Create a page with the page name being the same name of the password that you entered.

For example, I entered the password 'apple'. This generated the number 239552 and prompted me to create a page called 'apple.html'. It is important that the extension on the file is .html not .htm

3) Next, create the page with the information you would like to protect. In my case, I will create the page apple.html

Note: If the page you would like to protect is already created, then you must rename the page and use the password as the new filename.

4) You will need to download the file password.html (right-click and Save Target As...) and save it into your website in the same directory(folder) as your protected page.

Note: Be sure that when you save the file password.html it is saved as a .html file, not as a .htm file.

Note: To protect multiple pages, each page and its version of the password file must be in seperate folders, or you must change the name of the password file (rename "password.html" to "password2.html").


Now that you have your password created, the number written down, your protected page created, and the password.html file saved, it is time to work on the code required to implement the password protection.

5) Open password.html for editing and search the code until you find the section that reads:


if(code==239552) // code==[your access code]

6) Replace the number in red with the number that you generated earlier. Save the changes you made to the code then open the page you will use to link to your protected information.

7) Create a link, for example 'Members Only', and link it to the page you downloaded (password.html)

Members Only

Once you have placed the link where you like you are finished! You have just created a password protected webpage!

Note: If you are protecting multiple pages, be sure that your link is to the password.html file in the correct folder (if you are using multiple folders) or to whatever you renamed the file to (for example, password2.html).