Apache Guide: Apache Authentication, Part 4 Page 2

There are several ways to handle putting passwords into each type of
storage mechanism. In each case, you can do things "by hand", or you
can use one of the existing CPAN modules to do a lot of the work for
you.

The CPAN module to look for is HTTPD::UserManage. It was written
by Lincoln Stein and Doug MacEachern, and allows you to manage multiple
types of authentication mechanisms, on multiple server-types (Apache,
Netscape, etc) via one interface.

You can get HTTPD::UserManage from your favorite CPAN mirror. It also
comes with a CGI application that, when correctly installed, lets
you manage your authentication files from the web. Pretty cool stuff.

There are also a couple of other modules - Apache::Htpasswd and
Apache::Htgroup, that give a simple, Apache-only interface for managing
your authentication files.

Well, you say to yourself, that's pretty darned simple. Why would I want
to use a module to do that? Three reasons. One, if you're going to be doing
this hundreds or thousands of times, you'll find it much easier to be able
to call one function, passing in the username and desired password, than
encrypting the password yourself and running the above code. Secondly,
the modules provide you with a lot of other functionality, such as verifying
a password, and deleting a user. Thirdly, if you're using HTTPD::UserManage,
and you decide a year from now to change to using mod_auth_mysql instead
of htpasswd files, you don't have to change any code. That third one
is a big win, because some day you will want to change your authentication
method, and you don't want to be stuck with changing code a dozen places,
and potentially missing a few. Trust me. I missed a few.

DBM files are the fun ones, because they let me use a pretty cool feature
of Perl. Perl has a key work called tie. As the name suggests, it lets
you tie one thing to another. In this case, it lets you tie a variable
(in particular, a hash) to a DBM file. So, when you modify the hash, the
DBM file automatically gets modified for you. Very cool stuff.