As most of you might be knowing that htaccess can be used to password protect a directory on apache server etc. using htpasswd
In the past I used to do by sshing my host and using required commands.
Much easier is this using a php script:
For those who want to know about htaccess
Quick about HTACCESS
More comprehensive guide
Hope this will come in handy