Password Protecting site with .htaccess

Use the following as the template on your httpd-vhosts.conf file which is found in c:\xampp\apache\conf\extra.

<VirtualHost *>
  DocumentRoot c:/WebStorage/demo
  <Directory "c:/WebStorage/demo/">
    Options Includes Indexes FollowSymLinks
    AllowOverride all
    Order allow,deny
    Allow from all
    AuthType Basic
    AuthName "CU Intranet Demo Site"
    AuthUserFile "c:/WebStorage/passwd/.htpasswd"
    AuthGroupFile "c:/WebStorage/passwd/.htgroup"
    require group demo   

Managing Userid and Password file

htpassword.exe is located in c:\WebStorage\passwd

Create a new Password File

To create a new password file, use the -c switch and the name of the first user you want to add to the file:

htpasswd -c .htpasswd newuser

htpasswd will prompt you for the password. You are then asked for confirmation and if the two passwords match, the file will be created, and the new user will be added.
If you look at the file .htpasswd, you will see something like this:

Adding a new user to existing pasword file or change a password

To just add a user to your (already existing) password file, or to change the password of an existing user, use the same function without the -c switch.

htpasswd .htpasswd username

Removing a user from your password file

To remove a user from your password file, you need to open the file using your text editor and remove the line containing the userid and password.

Creating Group Files

Creating group file requires just a text editor. The format of the group file is the name of the group followed, colon followed by the list of the members of that group:

Managers: robert barry jim brian

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s