SHARE
Facebook X Pinterest WhatsApp

Apache Guide: Apache Authentication, Part 3 Page 2

Written By
thumbnail Rich Bowen
Rich Bowen
Aug 7, 2000
ServerWatch content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More



Note that you’ll be using the usual directives to set up password protection
on the directory:

        AuthType Basic
        AuthName "Members Only"
        require group admin

Auth_MySQL_DB [database_name]--Tells which
database you are authenticating against.

Auth_MySQL_Password_Table
[password_table_name]--Tells which table in that database contains
the password information. Unless you specify, it is assumed that the username
is contained in the field 'username', and the password is
contained in a field 'password'. You can change this. (See below.)

Auth_MySQL_Group_Table
[group_table_name]--Ordinarily, you'll probably just want to store
the group field in the same table as the usernames and passwords, but if you
need to store it in a different table, this is where you'll specify where that
is.

Auth_MySQL_Username_Field
[username_field_name]--If your username is a field other than
'username', you can specify that with this directive.

Auth_MySQL_Password_Field
[password_field_name]--If your password is a field other than
'password', you can specify that with this directive.

Auth_MySQL_Group_Field [group_field_name]--If
your group name is a field other than 'groups', you can specify
that with this directive.

Auth_MySQL_Encrypted_Passwords on/off--Tells
mod_auth_mysql whether the passwords are in the database
encrypted, or plain-text. This is on by default - that is, it is assumed that
your passwords are stored encrypted.

There are several other directives, but these are the main ones that you
will be using most of the time. The following is an example .htaccess file that
works for me:

        Auth_MySQL_Info localhost db_user db_password
        Auth_MySQL_DB   authentication
        Auth_Mysql_Password_Table       passwords
        AuthType Basic
        AuthName "Members Only"
        require valid-user

The above assumes that the username is in a field
username, and the password is encrypted, and is stored in
the field password.

Now What?

Once you have your .htaccess file set up as described above,
you will get the password dialog as normal. There will be no difference to the
user.

You can maintain your user and password lists via whatever database
management tool you are used to using. There's no handy tool like
dbmmanage for managing these accounts from the command line, but
I'm working on one.

You can use Perl and DBI to talk to your database. In my next column, I'll
be talking at greater length about using Perl to manage your password files.
There are a plethora of ways to do this, so it really merits its own article.

Summary

mod_auth_mysql allows you to keep your users, passwords, and
groups, in a MySQL database. MySQL is a lightweight, fast, free database server
which is available for most popular operating systems.

Future columns

Please let me know if there are other topics that you'd like for me to talk
about in future columns. You can send your suggestions to me at
ApacheToday@rcbowen.com And please
let me know what you think of my columns, at that same address. Many thanks for
reading down this far!

--Rich

thumbnail Rich Bowen

Rich Bowen is a ServerWatch contributor.

Recommended for you...

What Is a Container? Understanding Containerization
What Is a Print Server? | How It Works and What It Does
Nisar Ahmad
Dec 8, 2023
6 Best Linux Virtualization Software for 2024
What Is a Network Policy Server (NPS)? | Essential Guide
ServerWatch Logo

ServerWatch is a top resource on servers. Explore the latest news, reviews and guides for server administrators now.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.