How to password protect a website using .htaccess
Step-1. Create a text file for .htpasswd. This is the file in which you’ll be storing the username and password that people use to access the web page.
Step-2. Create your password using http://www.htaccesstools.com/htpasswd-generator. Storing passwords in plain text is unsafe, so you’ll need to use an online encryption tool to create a password.
- Enter the username into the “Username” field. This is the name the user accessing the website will enter when logging in you site.
- Enter the password into the “Password” field.
- Click to create .htpasswd file.
- You’ll now see the username and password separated by a colon. For example, if you entered “test_user” as the username and “test@123” as the password like this: test_user:$apr1$r9bza62g$rdSwoxvbO42JfP/8qyz7x/
- Copy the generated password in your .htpasswd file and save the file.
Step-3 In your .htaccess file following code add and save the file.
AuthType Basic AuthName "Protected Site" AuthUserFile /usr/home/yourusername/.htpasswd require valid-user
Output: