How to Password-Protect a Web Page

By eHow Internet Editor

Rate: (65 Ratings)

Password protection keeps only the users you want on your page. If you know JavaScript or even plain old HTML, you can use password protection.

Instructions

Difficulty: Easy

Placing a Link from an Unprotected Page to a Protected Page

Step1
Open the unprotected page in a basic text editor. Place the cursor where the link will appear.
Step2
Type the following, substituting your own text or graphic: Click here to access the password protected page.
Step3
Upload your file to the correct place in the file directory.

Creating a Script for the Password Page

Step1
Open a basic text editing program. Begin by typing the opening tags:
Step2
Type the title of your page and close the title with a tag: Protected Page: Please enter password
Step3
Type the following:
Step10
Close the scripted section of the page by typing the follow: .
Step11
Add a body section for browsers that do not read JavaScript: This page is designed for viewing with Firefox. Please upgrade your browser and return soon!
Step12
Close the Web page by typing: Save the page (for this example, save it as "password.html").

Creating the Error Page

Step1
Open a basic text editing program. Begin by typing the opening tags: </div> <div class="Part3 Step"> <div class="label">Step<span class="background"><span class="number">2</span></span></div> Title the page "Error" or "Wrong Password": <title>Sorry ' Wrong Password!
Step3
Type the error message the viewer will see, such as:

I'm sorry, the password you typed is incorrect.

Step4
Give the user an opportunity to re-enter the password: Please click here to try again. This allows the user the opportunity to return to the password script.
Step5
Allow the user to back out:

Otherwise, click here to return to the main page. ("here.html" indicates the name of the page that links to the protected page)

Step6
Close the page by typing the closing tags:

Testing the Password Script

Step1
Open a Web browser. Select Open from the File menu, locate the page that links to the password-protected page, and click Open to view it.
Step2
Click on the link to the password-protected page.
Step3
You will be prompted for the password. Make sure you enter it correctly; passwords are case-sensitive.
Step4
Gauge the results. If it does not work, go back and double-check that you entered the script correctly.

Finding More Complex Password-Protection Scripts

Step1
Visit pages that offer free JavaScripts and do a search for "password". Many of these scripts are just cut and paste, with minimal changes.
Step2
Protect extremely sensitive information by hiring a Web developer (or your ISP) to create a customized password script for you. These scripts are extremely sensitive and very difficult for hackers.
Step3
Contact your Internet Service Provider and ask if they provide password protection services. This entails setting aside a portion of the server for your pages, so some ISPs may charge extra.
Step4
If you use a free script, add a courtesy button or reference to the provider on your page.
Step5
You may need to get permission before using JavaScripts from another Web site. When in doubt, ask!
Step6
Not all browsers support scripts. Be sure to follow directions for providing alternates to scripts on your Web page.

Tips & Warnings

  • Users must click on a link to access a page unless the first page of a site is protected. If the main page is the password protected page, start at Section 2.
  • For the purposes of this section, the destination of the link, a script file, is called "password.html".
  • Users who enter the correct password are taken straight to the page; users who enter the incorrect password are sent to an error page. You create the error page, called "error.html" here, in the next section.
  • Be sure to enter all commands as shown. JavaScript will not work if the command isn't exactly right.
  • Format this page to resemble your other pages, so viewers don't get lost.
  • Try typing both the correct and incorrect passwords so you will see what your visitors see.
  • Do not link back to the password file (password.html). If the person does not know the password, they will be endlessly looped and cannot get out of the script.

Comments

| View All Comments

denmark said

Flag This Comment

on 3/11/2008 what happened to this article? parts are missing.

Flag This Comment

on 12/11/2006 Tried this on my website.

It DOES NOT work !!!!

Not sure why ...but when you type in any word instead of the password, the protected webpage still opens !!

Anonymous

Anonymous said

Flag This Comment

on 8/8/2006 Instead of using the code: var password = prompt("Enter in the password"""); it should really be: var password = prompt("Enter in the password","");
Please note the comma after the first double quote after "enter password" ... without this comma, the script does not run.

Anonymous

Anonymous said

Flag This Comment

on 8/3/2006 1. Encrypt page text using password (by javascript), and decrypt it using password provided by visor. Content will be good only when password is correct. Drawback: user with javascript disabled will not be able to see your content.

2. Protect the page on server. I'm using one password protection tool which does it very good. It requires a password only once if you protect fewer pages with same the same password.

Anonymous

Anonymous said

Flag This Comment

on 3/8/2006 To find out the passwrd : View the source of the document (Right-click on the link > Copy Link Location // Then, in your browser's address bar, type view-source: and press Ctrl+V, then Enter) > Ctrl+F > if(pasword=" > Enter >
You got it.

View All

Post a Comment

POST A COMMENT

Request a New How-To Article

Looking for more How To information? Chances are there’s an eHow member who knows how to do what you’re looking to do. Submit an article request now!

eHow Article:  How to Password-Protect a Web Page

eHow Internet Editor

eHow Internet Editor

Category: Internet

Articles: See my other articles

Related Ads

Create Your First Web Site

How to Create Your First Web Site
By: eHow Internet Editor


Learn About Java

How to Learn About Java
By: eHow Internet Editor


Learn About JavaScript

How to Learn About JavaScript
By: eHow Internet Editor


Learn HTML

How to Learn HTML
By: eHow Internet Editor


Add a Link to a Web Page

How to Add a Link to a Web Page
By: eHow Internet Editor


Internet

Veesites
Meet Virginia DeBolt eHow’s Internet Expert.