Use this tool at
Dynamic Drive
to automatically generate all the code needed to protect a directory on
your site. Below are the 2 files generated by the tool. .htaccess goes
into the folder that you want to protect and .htpasswd should be in a
folder not accessible from the web. I normally put my .htpasswd file in
my apache’s base folder.
.htaccess file
AuthName "Restricted Area"
AuthType Basic
AuthUserFile /home/mydir/.htpasswd
AuthGroupFile /dev/null
require valid-user
.htpasswd file
danny:8UAaVrlw.58f6
Get the tool here.