Password Protect Directory

Problem

How to password protect a directory

Solution

To make the whole directory protected with the password, you need to have an .htaccess which has the followings:

AuthName "Protected Area"
AuthType Basic
AuthUserFile /path-to-site/.htpasswd
require valid-user

and then the .htpasswd with the username and password but the password needs to be encrypted here is the link to generate encrypted password