1000 FAQs, 500 tutorials and explanatory videos. Here, there are only solutions!
Securing Web Access with a Password
This guide explains how to protect a part of a site on a Web Hosting by requiring a password before accessing a directory (including subdirectories) from a browser.
Simple Method
Protect a directory with a password (Digest authentication) using the "Folder Protection" tool:
- Click here to access the management of your product in the Infomaniak Manager (need help?).
- Click directly on the name assigned to the relevant product.
- Click on Security in the left-hand menu.
- Click on Folder Protection in the left-hand menu.
- Click on the directory to be protected.
- Enable protection using the toggle switch, then create one or more users*:
- * Users are defined per directory; the tool does not allow managing groups of users:
- * Users are defined per directory; the tool does not allow managing groups of users:
- Click on the Add button.
- Click the button to Add an Access for an additional user if necessary.
- Click on the action menu â‹® to the right of the relevant user to edit or remove them.
- Click the toggle switch again to completely disable the folder's protection:
Manual Method via .htaccess
Protect a folder with a password using your site's .htaccess
file:
1. Choose and Encrypt the Password
- Log in to your hosting via an FTP software/client or the FTP Manager.
In the folder to be protected, create a file named
password.php
and adapt the following content inside it by replacing12345
with the desired password:<?php $pass = "12345"; echo password_hash($pass, PASSWORD_DEFAULT); // Displays the hashed password ?>
- Open a web browser and display the
password.php
file (e.g.,domain.xyz/folder_to_protect/password.php
). - The web browser displays your hashed password; copy it as it will be needed in step 3...
2. Create the .htaccess File
In the folder to be protected, create a file named .htaccess
and adapt the following content inside it:
AuthName "Protected Admin Page"
AuthType Basic
AuthUserFile "/example/.htpasswd"
Require valid-user
Replace /example/
with the absolute path of the folder to protect. Example:
AuthUserFile "/home/clients/0f83c7afb710e5ae2645a1b704d8772f/web/folder_to_protect/.htpasswd"
3. Create the .htpasswd File
In the folder to be protected, create a file named htpasswd.txt
and adapt the following content inside it:
login:hashed_password
- Replace
login
with the desired login. - Replace
hashed_password
with the hashed password copied in step 1 of this guide.
Once the htpasswd.txt
file is saved, rename it as follows: .htpasswd
.
4. Test the Login
Open a web browser and try to access one of the pages in the protected folder. If the guide has been followed correctly, the chosen login and (non-hashed) password will grant access to the protected folder.
Other restrictions can also be applied using .htaccess
.