First create .htpasswd file for allowed users. You can create .htpasswd file using one of the following ways:
- By using command line
htpasswd [-m | -d | -s | -p] /path/to/passwdfile/ <username>
Above command will prompt for password. Given password will be assigned to <username>
-m : Use MD5 encryption for passwords
-d : Use crypt() encryption for passwords
-s : Use SHA encryption for passwords
-p: Use plaintext passwords - By directly editing .htpasswd file
open the file .htpasswd and add like username:password -> then save and close.
This will store password in plaintext format.
Ref. URL: http://httpd.apache.org/docs/1.3/programs/htpasswd.html
Now Modify .htaccess which is placed into directory which you want to protect to refer htpasswd file as authenticated user.
Add the following in .htaccess file
AuthName “Restricted Area”
AuthType Basic
AuthUserFile /path/to/.htpasswd # full path to .htpasswd file
AuthGroupFile /dev/null
require valid-user
Now whenever anyone try to access directory or sub-directories in which .htaccess file is place then browser will prompt for HTTP Authentication Popup.
Please Note: Above will only work on Linux OS.
For more information please refer: http://mitulmpatel.wordpress.com/2009/11/20/htaccess-useful-tricks/
Post comment if you have any problem.
