Password Protecting a web directory with htaccess
How to password protect a directory?
- Go to the directory you want protected.
- Check if you have a .htaccess file.
- If a htaccess file is available, you have to edit it, otherwise create a new .htaccess file.
- Add the following to the htaccess file:
AuthName “Tech and Dev Example”
AuthUserFile: this is the path of the .htpasswd file where the username and password will be stored. The file can be located anywhere, but ideally, it’s better if it’s placed in a non public directory where users can’t access it from the web.
AuthType: should be Basic
AuthName: The title of the window that will be authenticating the user. For example if you’re password protecting your private files, you might want to change this to “My Private Files”.
#htpasswd -nb username password
How is the password getting encrypted?
Any questions or suggestions? Please leave a comment below!