Home Apache PHP Ubuntu MySQL Linux HTML Win CSS Perl Javascript Rants Retro
 
Print This Page
Date Posted: Monday 12th of December 2011 | Category: Apache
Password protect a directory on your webspace
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>


Change the AuthUserFile to the path on your own server.
Change the AuthName to whatever you want. No spaces
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.
Related Links:
- Generate a .htpasswd file