Password Protect Directories
This is a common question that comes up very often. How do I password protect a
directory? The answer is actually very simple. If you are not able to password
protect your directory through your host's control panel follow these simple
steps:
First you will have to create a text file, and rename it ".htaccess".
After you rename the file, edit the file by adding the following code:
AuthUserFile /somedirectory/.htpasswd
AuthGroupFile /dev/null
AuthName Password Protected Area
AuthType Basic
<LIMIT GET>
require user admin
</LIMIT>
The bottom three lines indicate that only the user admin can access the
directory this file is in. The top line contains the location of the
password and username for admin (/somedirectory/.htpasswd). The AuthGroupFile
line is used when you want to have multiple usernames. In this case, there is only
one user name, so we point this line to /dev/null. The third line is the title
of the authentication message box that pops up, while the fourth line indicates
that this uses Basic authentication.
Using an FTP program, upload this file to the directory that you wish to
protect.
The second file that needs to be created is a text file that must be renamed
to ",htpasswd". This file must be uploaded in location specified by the top line
(/somedirectory/.htpasswd).
To generate content for the .htpasswd file I suggest this website:
http://home.flash.net/cgi-bin/pw.pl
If you do have access to "htpasswd", then the above file would be created like
this:
htpasswd -c /somedirectory/.htpasswd admin
You would be asked to type in the password, the appropriate file would be made.
For Multiple Users:
The ".htaccess" file should read:
AuthUserFile /somedirectory/.htpasswd
AuthGroupFile /somedirectory/.htgroup
AuthName Admin Area
AuthType Basic
<LIMIT GET>
require group allowed
</LIMIT>
"AuthGroupFile" now points to a file called ".htgroup", instead of
/dev/null. Also, the "require" line names a group name ("allowed") instead of a
single user name such as (Admin).
Next, the ".htgroup" file needs to be created:
The content of the ".htgroup" file should look like the following:
allowed: admin andrew bob emily
The usernames "admin", "andrew", "bob", and "emily" are now able to access the
protected directory.
Finally, the ".htpasswd" file must be created.
Use the recommended website to generate content. Each generated output should be
on a separate line.

