How to Create HTML Password Protection

It is possible to place password protection on html.files, by using a built in system of password protection. This provides some means of securing some of your documents.


If you want to restrict files in a directory foo to a person with username slakker, and password slack, this is how you would do it. You would need to create a file .htaccess in the directory foo. The contents of that file would be:

AuthUserFile /otherdir/.htpasswd
AuthGroupFile /dev/null
AuthName ByPassword
AuthType Basic

<Limit GET>
require user slakker
</Limit>
The password file will be in another Directory(/otherdir) AuthUserFile must be the FULL UNIX PATHNAME of the password file(no ~ expansion).

AuthName can be anything-and should be descriptive AuthType should be set to Basic

Now you need to create the password file:
Use the command: /usr/local/etc/httpd/support/htpasswd -c /otherdir/.htpasswd slakker. Then type the password as requested.
to add other users to the password file, remove the "-c" flag, and you can append other users.