I wanted to password protect a folder on my webspace. Unfortunately my hosts did not provide this as a function on my hosting control panel. Setting up a password protected folder is quite straight forward. The first thing you need to do is create an .htaccess file.
Create an .htaccess file and enter the following code.
AuthUserFile /home/user/www/.htpasswd
AuthName ProtectedArea
AuthType Basic
<Limit GET POST>require valid-user</Limit>
1) Change the AuthUserFile to the path on your own server.
2) Change the AuthName to whatever you want. No spaces
3) Save the file .htaccess
As you can the AuthUserFile points to a file called .htpasswd
As the name suggests this is where your username and password will be stored. The next thing we need to do is create the .htpasswd.
To generate the password you may need to visit a website.
I found the following site at http://www.htaccesstools.com/htpasswd-generator/
Enter the username and password.
Copy the code on the next page. The username and password is in the following format.
test:$apr1$lwFL0YZG$Nps4uKqMX8.QDu2wXk.C51
Now that you have copied the code, copy this in to a file and save it as a .htpasswd file.
You should now have two files. .htaccess and .htpasswd. Connect to your webspace and upload these to your root directory.
If everything was succesful you will be prompted for your username and password.