So now, what i do here is what was advised from one of my friend.
You need to just add the following lines to httpd.conf file in /etc/apache2/
AuthName "Restricted Access"
AuthType Basic
AuthUserFile /etc/passwords/.htpasswd
Require valid-user
/var/www/restricted is the directory which contains webpages or files which needs user authentication for viewing or for downloading. You can Give anything for AuthName in quotes. /etc/passwords/.htpasswd is the file where the username and passwords(encrypted) are placed. You could store this information anywhere you want but specify the location at AuthUserFile.. It should be .htpasswd file.
Now we create the .htpasswd file with a command
:#htpasswd -c /etc/passwords/.htpasswd username
You would be then prompted to enter the password
New Password : guest
Re-type new Password : guest
Adding password for user username
so the -c option creates the .htpasswd file if not present and adds the user. The next time you use htpasswd for the same location you need not use -c option...So now only those users would be able to access the restricted pages and files.
if you do a cat on the .htpasswd file, it would look as below..
username:uxl0NERvhkPgI