Apache: authentication on windows with .access and .htpasswd

If you want to restrict access to a directory under apache then theses lines are for you…

In the directory you want to activate the authentication you must create the following two files:

.htaccess
AuthUserFile C:/Apache2.2/htdocs/directory_to_secure/.htpasswd
AuthName “Description to appear on the auth window”
AuthType Basic
Require valid-user

.htpasswd
a_username:$apr1$EB2…..$gd7dlEPO.dGPr2LGKqvpL1

Notes:
- In the “AuthUserFile” directive of the .htaccess file you should separate directories with “/”
- The format of the .htpasswd file is simple. Notice that it is just a username followed by an encrypted password, separated by “:”

How can I get the .htpasswd password?

Well, there are at least two ways. You can compute that with your brain :-) or you can open a windows shell (with “cmd” on the start/run), go to the “bin” directory of the apache installation and type:

htpasswd -c -b password.txt my_user my_password

where you must change “my_user” to your username and “my_password” to the desired password.
A file “password.txt” is then created containing the line that you should place inside your .htpasswd file. You can place as many users as you want but remember to place each one in a new line.

Hope it runs well.

by LSimpson

Leave a Reply

You must be logged in to post a comment.