How To Make Any Webpage Password Protected

 This is the easiest way to make a password-protected page if you don't know how to do coding and make a login page. If for some reason you want to password protect your website or any specific page then follow the steps.

Make a webpage password protected


Create the username and password

First, you need to create a .htpasswd file. You can create the file on your computer and upload it later to your host or you can create the file directly in your WebHost. we are going to create the file on the computer for this tutorial and upload it later to our WebHost. You can use Notepad to create the file. Create a txt file and name it as .htpasswd. Your file will look like this .htpasswd.txt.

Now we need to write the username and password information in the file we have just created. You should encrypt the password instead of typing it in plain text for security. To do that go to this website and fill in all the information like the below picture. Select the mode to MD5 if you are using an Apache server, but it is optional. 

Creating encrypted password


It will generate an encrypted password along with the username for you. Copy the whole code and paste it into the .htpasswd file. Now you need to upload this file to your web server. But remember, do not upload this file to a directory which is accessible from the web. Otherwise, someone with enough knowledge will be able to unlock your website anytime.

Before you upload the file, rename the file and remove the .txt from the file name and after that, your file will be looking like .htpasswd.

Lock the webpage 

Now we need to lock the webpage using the username and password we have created before. To do that we need to create a .htaccess file and upload it to the directory you want to lock. Suppose you want to lock the https://yourweb.com/secret directory. For that, you have to upload this file to the secret named directory in your web server. 

Now open your Notepad again and copy and paste the below code in it. 

AuthType Basic
AuthName "Protected Site"
AuthUserFile /usr/home/yourusername/.htpasswd
require valid-user

Replace the /usr/home/yourusername with your actual location of the .htpasswd file. Now to save the file, go to save as then select the file type to All and name it as .htaccess then save it. Thus you don't have to rename it from txt file.

Create .htaccess file

Okay, now we are all done. You just have to upload this file to your desired directory and it is all done. Now visit that directory to make sure it is working. 

That is all. If you got any issues while doing this let me know by doing a comment.



Post Comment

Comments