What is Password Protection
When Should You Password Protect Pages?
With HTAccess, you can password protect any page or directory on your Web server. You can even protect the entire website if you want to. HTAccess is the most secure method of password protection, as it relies on the Web server, so the valid usernames and passwords are never shared with the Web browser or stored in the HTML like they can be with other scripts. People use password protection:
- Hiding new versions of your website from the public until they are ready to launch.
- Protecting private sections of your website so that only people you know and trust can read them.
- Providing paid content to your customers and only allowing access via a password.
- Creating a private forum for select readers.
It's Easy to Password Protect Your Web Pages
You need to do two things:
- Create a password file to store the usernames and passwords that will have access to the directory.
- Create an htaccess file in the directory to be password protected.
Create the Password File
- Open a new text file called
.htpasswdNote the period at the beginning of the filename.
- Use a password encryption program to create your passwords. Paste the lines into your .htpasswd file and save the file. You will have one line for every username that requires access.
- Upload the .htpasswd file to a directory on your Web server that is not live on the Web. In other words, you should not be able to go to http://YOUR_URL/.htpasswd - it should be in a home directory or other location that is secure.
Create the htaccess File
- Open a text file called
.htaccessNote the period at the beginning of the filename.
- Add the following to the file:
AuthUserFile /path/to/htpasswd/file/.htpasswd AuthGroupFile /dev/null AuthName "Name of Area" AuthType Basic require valid-user
/path/to/htpasswd/file/.htpasswdto the full path to the .htpasswd file you uploaded in above.
"Name of Area"to the name of the site section being protected. This is used primarily when you have multiple areas with different protection levels.
- Save the file and upload it to the directory you want protected.
- Test that the password works by accessing the URL. If your password doesn't work, go back to the encryption programs and encrypt it again. Remember that the username and password will be case-sensitive. If you are not prompted for a password, contact your system administrator to make sure that HTAccess is turned on for your site.