Development Island

How to setup password protection for a directory

The following steps detail how to password protect a directory using htaccess.
  1. First you will need decide which directory to protect, in this example we want to protect the following web address:

    http://www.jblogss.devisland.net/private

  2. On your local machine create a file titled "htaccess" (Note: no dot "." in filename) and put the following content in it:
    AuthType Basic
    AuthName "Restricted Files"
    AuthUserFile /home/jbloggs/htdocs/private/.htpasswd
    Require valid-user
    								
    You will need to change "jbloggs" to your own username and "/private" to your own directory you wish to protect.

  3. Now upload this file to the directory you wish to protect, which in this example is "/htdocs/private".

  4. Rename the file on the server so it is called ".htaccess" (Note: don't forget the dot "." in the name).

  5. Now you need to create a password file called "htpasswd" (Note: no dot "." in filename) on your local machine.

  6. Open the file in an editor such as Notepad and then browse to the following link:

    htaccess info and password generator from AddedBytes

  7. Using the form on the above page, enter the required username and password for the page protection. After clicking the "Encrypt" button you will see the encrypted password generated like the one below:
    jbloggs:1$NbzIz4XKCNQ
    								
    Copy and paste this text into your "htpasswd" file.

  8. Repeat the above step until you have added all of your required users to your "htpasswd" file.

  9. Upload the "htpasswd" to your protected directory (the same one you uploaded the ".htaccess" to).

  10. Rename the file on the server so it is called ".htpasswd" (Note: don't forget the dot "." in the name).

Your directory should now be protected and only accessible to the users you entered in the ".htpasswd" file.