.htaccess is a configuration file working in Apache to provide a way to make configuration change per directory.
Username / Password Protection
Apache Configuration File<Directory "/home/www/www.foo.com/htdocs"> AllowOverride All Options +Includes </Directory>
.htaccess File
AuthUserFile /home/www/www.foo.com/htpasswd AuthName "Secret Area" AuthType Basic require valid-user
Create htpasswd file
htpasswd -c /home/www/www.foo.com/htpasswd johndoe
Restrict by IP Address
.htaccess File
AuthName “Secret Area”
AuthType Basic
order deny,allow deny from all
allow from 192.168.