You can protect your directory or website by .htaccess and .htpasswd file
For password protecting directory also need a file to contain username and password which allowed to access the website, this file to called ".htpasswd". htpasswd placed anywhere on server.
AuthType Basic AuthName "Password Protected Area" AuthUserFile /home/public_html/.htpasswd Require valid-user
<Files test.php> AuthName "Password Protected Area" AuthType Basic AuthUserFile /home/public_html/.htpasswd Require valid-user </Files>
<FilesMatch "^(test|welcome|login).php$"> AuthName "Password Protected Area" AuthType Basic AuthUserFile /home/public_html/.htpasswd Require valid-user </FilesMatch>
username:password
You can choose hashing algorithms for password
Username is "admin" and password is "test", it is converted in md5
admin:098f6bcd4621d373cade4e832627b4f6