.htaccess Password Protection

The .htaccess authentication or .htaccess password protection is the method in which we can protect our folder or directory. We just need to create a text file with the name .htpasswd and write few lines of code in it. Then we upload both .htaccess and .htpasswd files in the specified directory for which the password protection is required.

  • AuthType Basic
  • AuthName “Password Protected Area”
  • AuthUserFile /path/to/.htpasswd
  • Require valid-user

You just need to replace the “/path/to/.htpasswd” with the full path to your .htpasswd file. You can find the full path using PHP and make changes by yourself but to avoid serious damages you can get help by our professionals. Then you need to upload the .htpasswd file into the password protected folder. Please double check that your .htpasswd file has the username and password into it. The .htpasswd file should contain:

  • test:dGRkPurkuWmW2
  • The above mentioned code will grant the user “test” to approach the password covered portion with the password “test”. The text “dGRkPurkuWmW2” is an encrypted version of the password. You will need to use htpasswd generator to create new password. Every line in the .htpasswd file contains a username and password combination, so do not hesitate to add different and required combinations.

    Use Automated Authentication Generator

    You can use the htaccess authentication generator too to create .htaccess file for password protection.