Sometimes it’s needed to make a folder password protected to enhance security. Let you have a site with admin end where admin area is already password protected using script but you extra security. Or you have a folder with url http://www.mydomain.com/privateimages/ which is accessible to certain user with given access. This can be done easily using htaccess.
To do this you have to create two files. One file is .htaccess file which will contain information of user access file. Let the username, password’s information file is .htpasswd . First create the .htpasswd file using any text editor. Generate username and password and put them inside your .htpasswd file. There are a list of online tools which generate .htpasswd username and password. Just use google search for them. http://www.google.com/#hl=en&q=.htpasswd+Encryption+Tool&aq=f&oq=&aqi=&fp=Yxcf45uQ1Fc
Ok, now you have the .htpasswd file ready. Upload it on your host root folder or somewhere else which is very secured and inaccessible through url. Now create .htaccess file. Put the following code( modification needed with your aspects)
AuthUserFile /home/user/.htpasswd AuthGroupFile /dev/null AuthName “Private Area” AuthType Basic <Limit GET POST> require valid-user </Limit>
This is pretty straight forward and self-explanotory. You have to modify the first line to locate your .htpasswd file. After make this file ready, upload .htaccess file to that folder which you want to protect.