A DB-Based User Registration System
By Brian Wilson
Web sites often need user databases. Maybe your site has a members-only area, or maybe you send out a newsletter to keep users informed when you update your site. In any case, you have to maintain the user information on your server. However, if the user is allowed to update his or her own information, the task of keeping data current will be simplified.
There are several approaches you can use to implement a user database. You can keep all the information in a single flat file. This works adequately for small sites, but performs poorly for large ones. For a large site, you can use a full SQL database system. A SQL-based system will give you good performance, but it's expensive to implement and a challenge to use.
There's a third alternative based on the Berkeley DB package that's easy to implement but still offers the performance of a relational database system. That's what I'll show you in this article.
At O'Reilly Networks, we use the Apache Web server, running on Red Hat Linux servers. We're in the process of updating them but they are currently all flat-file based. The Apache authentication system uses a single file with all username/password pairs listed in it, one entry per line. To keep track of the additional user information (typically name and address info), we rely on a system with one file per user. This system works adequately until you accrue more than 500 users; at that point, it starts to become less attractive for several reasons.
First off, accessing a flat password file to look up a username/password pair requires a linear search through the file, so the average time to look up a record to perform an authentication will increase as the number of users grows.<>