How do I require users to enter a password to access a webpage?

Overview: You can protect parts of your website from public viewing by requiring users to first enter a correct username and password before accessing them. This allows you to offer information and access for sale, as well as to distribute sensitive or confidential information to only certain people.

Before Beginning
Group the pages you wish to protect into a single directory (folder) in your www directory.
Follow these steps
  1. Login to your Netmar account through telnet (see Question 1.9)
  2. Type:
    htpasswd -c passwords.txt username
    and press ENTER. Replace username with a 3-8 character username you wish to create for a user to access your restricted area. Create and enter a password for that user. You will be asked to type it twice without seeing it, so type carefully.
  3. If you wish to add additional users, type:
    htpasswd passwords.txt username
    and press ENTER. Replace username with a 3-8 character username you wish to create for a user to access your restricted area. Create and enter a password for that user. You will be asked to type it twice without seeing it, so type carefully. You should omit the -c from the command this time and any other time AFTER the first user is added to the password list.
  4. Type:
    cd www/somedir
    and press ENTER. Replace somedir with the name of the folder where your restricted files reside.
  5. Type:
    restrict "My Protected Area" ~/passwords.txt
    and press ENTER. Replace "My Protected Area" with some text you would like to appear on the login window users will see.
  6. Optionally, you may want to create a code 401 error document so that users who enter an incorrect password will see your own custom message instead of the system default. See Question 2.9 for details.