1) Edit .htaccess file as follows:
Order Deny,Allow
Satisfy All
# BASIC BLOCK - Note you may need AuthDigestFile instead of AuthUserFile
AuthType Basic
AuthName "Auth Name" #e.g.protected by apache
AuthUserFile physical path to .htpasswd file #e.g. C:/xampp/htdocs/~/.htpasswd
Require user username
2) Use following command to generate .htpasswd file
htpasswd -c .htpasswd username
3) Place .htaccess file in the directory which needs authentication access