In this short and easy guide we will be explaining how to password protect your directories using a .htaccess and a .htpasswd file.
Steps to take
- Create a file named passwordhash.php and add the following code to it:
- Upload the file to your domain via FTP
- Visit the page you just created and make a copy of the hash.
- Open a text editor such as Notepad++ and add the following: user_name_here:hash_here
- Save the file as .htpasswd (Please ensure that you have the file type set to All types) and upload it to your domain via FTP.
- If you don’t already have one, create an .htaccess file and upload it to your domain.
- Add the following contents to the file:
- Delete the passwordhash.php you created earlier on.
<?php // Password to be encrypted for a .htpasswd file $clearTextPassword = 'your_password_here'; // Encrypt password $password = crypt($clearTextPassword, base64_encode($clearTextPassword)); // Print encrypted password echo $password; ?>
Where your_password_here is replaced with the password you wish to use.
Your .htpasswd contents should look similar to the following
AuthType Basic AuthName "Password Protected Area" AuthUserFile /hsphere/local/home/YOUR_ACCOUNT_USERNAME/YOUR_DOMAIN/.htpasswd Require valid-user
Replacing YOUR_ACCOUNT_USERNAME & YOUR_DOMAIN respectively.
That’s it, visiting your domain should now prompt you for a username and password
As always, please leave us any questions in the comment section below.
Rate this post