Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

How to Protect a Folder on Your Website with a Password

This guide shows you how to lock a folder so visitors must type a username and password before they can open it.

How-To Guides2 min read17 steps5 screenshots

What is a protected directory?

A directory is just a folder on your web hosting. Normally anyone with the link can open what is inside. When you protect a folder, the browser asks for a username and password first. It is like a door with a lock. Only people with the key can go in.

Steps in the control panel

Most hosting control panels have a tool for this. In cPanel it is called Directory Privacy (or Password Protect Directories). Your welcome email says which panel you have.

  1. Log in to your control panel.
  2. Find the Directory Privacy tool and open it.
    Screenshot: Find the Directory Privacy tool and open it.
  3. Choose the folder you want to lock. Click its name to open it.
  4. Tick the box Password protect this directory.
    Screenshot: Tick the box Password protect this directory .
  5. Type a name for the folder. Visitors will see this on the login box.
  6. Click Save.
  7. Under Create User, type a username.
    Screenshot: Under Create User , type a username.
    Screenshot: Under Create User , type a username.
  8. Type a strong password. Use a mix of letters, numbers and symbols.
  9. Click Save.

Test it

  1. Open a private or incognito browser window.
  2. Visit the folder address, for example yourdomain.com/private/.
  3. A box should ask for a username and password.
  4. Type the details you made. The page should open.

How to remove the lock

  1. Go back to Directory Privacy.
    Screenshot: Go back to Directory Privacy .
  2. Open the same folder.
  3. Untick Password protect this directory.
  4. Click Save.

What happens behind the scenes

The panel makes two small files. One is .htaccess, which tells the web server to ask for a login. The other is .htpasswd, which stores the usernames and scrambled passwords. Do not delete them by hand unless you know why.

Tip: Password protection is good for private files, test sites and client previews. It is not a replacement for a full login system on a busy site.

Quick recap

  • A protected folder asks for a username and password.
  • Use Directory Privacy in your control panel.
  • Pick the folder, tick the box, add a user and save.
  • Test in a private browser window.