How To Password Protect A File Or Folder And Stop Snoopers


We need to password protect a file on our website that only allows access to Members.

How do we achieve this?


The easiest way to do this through cpanel (web hosting control panel).

Here are the steps:

1. Create a folder on the server containing the file that needs to be protected. For example the folder name is “Members” and the file name is “index.html”

2. Login to cpanel

3. Click on “password protected directories”

4. Under ‘security settings” check the box “Password protect this directory.”

5. Under “Name the protected directory” give a name to your directory. This name will pop-up when users login in.

6. Click “save” to save your settings.

7. Under “Create User” specify a username and password

8. Click “add/modify authorized user.”

9. Test the protected directory by entering the URL in your browser

10. A box will appear asking for a username and password. You’ll gain access to the protected file after logging in.

Note: You can place any type of sensitive files in the directory so it can be protected from snoopers.

Manual Method

1. Create a file named .htpasswd and place it in folder which contains the file to be protected.

2. Put the username and encrypted password inside the .htpasswd file as


3. Place the following code in your .htaccess file, in the same folder where you want to protect the file.


<FilesMatch "file.html">
AuthName "Member Only"
AuthType Basic
AuthUserFile /home/cpanelusername/.htpasswd
require valid-user


4. Test access to your file by entering the URL to your file in your browser address bar.

5. Enter your login info in the box that appears

6. You should now be able to view your protected file

7. Only give your login info to the members who can gain access.

Read my follow-up article on
How to Prevent Your Forms From Being Stolen