This document is obsolete and is retained for reference purposes only. It will not be maintained. The information contained should also be considered obsolete.

Converting a CSV File to .htpasswd/.htgroup

A CSV file is a "Comma Seperated Values" file. These are easily created with standard database and spreadsheet applications. The NEWxxx.DAT file, part of the current shipped rosters from national, is actually a CSV file, but may need to be renamed (from a .DAT to .CSV) before being opened by your spreadsheet or database application.

The Perl script is used to convert a CSV file containing 3 fields:

  1. certificate number
  2. last name
  3. email address
into the corresponding .htpasswd and .htgroup files. Please refer to your spreadsheet or database application's manuals for more information on creating a CSV file containing the 3 required fields.

A seperate template .htaccess file will need to be editted to enable the web server's authorization directives.

The "user name" will be the certificate number, and the "password" will be the email address. The last name is used to salt the crypt() function.
  • The email (and last name) may be used by more than one member of a family, so it can not be considered unique. The certificate number is, so we neccessarily must use it for the user name.
  • A half-hearted attempt at guessing the input list file's format will be made. Supported formats are 3 (certnumb,lastname,email), 4 (same, but with firstname in there) and 58 (standard newXXX.dat format).
  • We will use the "Sample Site Power Squadron" as the example.
  • The squadron has its web site on the ITCom server and its URL is
  • Therefore, we know that the web document directory is /doc/samplesiteps/. This is different than your "home" directory.
  • Let's also say that the directory to be protected is called formembersonly. The "full path name" is then /doc/samplesiteps/formembersonly/.
  • Let's assume that you have already telnet'ed (or ssh'ed) into the ITCom server. Do not forget that the ITCom server is a UNIX (Linux) system, so upper- and lower-case is important. Type commands and file names exactly as shown.
  • Please review the "Sites Hosted on the ITCom Server" policy available from the ITCom web site if this is confusing.

Get to your web document directory - not your home directory:
cd /doc/samplesiteps

If it has not yet been created, create the formembersonly directory:
mkdir formembersonly

All the files to be protected - as well as the perl script, your CSV file, and the .ht-files - will reside in this directory:
cd formembersonly

Copy the perl script from the ITCom directory to your working directory and make it executable.
cp /nat/itcom/shared/help/samples/csv2htpasswd.txt ./
chmod +x

Now that the perl script is there, you will need to transfer in your CSV file. Use your ftp program from your desktop and put the CSV file into this subdirectory.

Run the perl script and convert your new CSV to the corresponding .htpasswd and .htgroup files, passing as the single command line argument the name of the file you just ftp-ed in:
./ yourfilename.csv

Now that you have a list of valid users (.htgroup) and an encrypted password file (.htpasswd), you should remove the readable, unencrypted, source CSV file:
rm yourfilename.csv

Hint - don't bother deleting the script. Whenever you make a change to your list of members with email addresses, you can ftp the updated CSV file and execute the script to recreate the group and password files.

Copy the template .htaccess file from the ITCom directory.
cp /nat/itcom/shared/help/samples/htaccess.txt ./htaccess.txt

Note - do not copy this to .htaccess yet. The file is a template and the web server will begin to enforce the rules with incorrect data. This text file will be renamed a little later.

Edit the text file using your favorite text editor. If you have a problem with the editors on the UNIX server (ed, ex, sed, vi) you will have to ftp the text file back to your desktop, edit it there, and ftp it back to the ITCom server.

You will need to change the first 2 lines. These are the ones that refer to the formembersonly directory name.

Actually, you need to change the 3rd line too. Make sure the real squadron name is there and in quotes.

Once you are finished with the template file edits (or ftp'ing the text file around), move the template to .htaccess. Once the file is in place, the web server will begin enforcing the rules.
mv htaccess.txt .htaccess

Hint: This file only needs to be editted once. Even when users are added or deleted, this file does not change - only the group and password files do.


Now, when visitors try to access any page in the formembersonly directory (or any subdirectory), they will be presented a standard user name (certificate number) and password (email address) dialog box by the web server before being granted authorization to recieve the files.

Optional: If you are concerned that your members may not be able to fill in the dialog properly, and would like to provide them a friendly error page instead of the generic "Unauthorized" (error 401) error provided by the web server, you must add a directive to the .htaccess file.
ErrorDocument 401 /localusps/samplesiteps/accessdenied.html

It is important to note that you must provide this referenced HTML file and it is a URL, unlike the other lines in the .htaccess file.
Privacy | Trademarks | Disclaimer | Contact | ©2006 United States Power Squadrons