Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to limit access to certain directories served by Apache. I want the client to have to type a username and password, but then I want Apache to take the username and password that the person typed and pass them as arguments to a python script that I wrote to do the authentication. Then, based on the output of said script, I want Apache to either allow or deny access. Is this possible?

share|improve this question
up vote 3 down vote accepted

The only way I know of to do this is using mod_auth_external or mod_python. The first allows you to implement custom authentication systems; the latter gives Apache an embedded Python interpreter, which can be used to write a custom authentication script. Neither are standard, or very popular, modules.


the easiest would be to simply have your authentication system update the password list that Apache uses. Apache comes with all the tools you need to add/update/delete users from either an .htpasswd or .htdigest file (it should be trivial to hook the htpasswd or htdigest commands into any user management system).

Or, you can have mod_auth (Apache's default authentication system) read from a database via the following modules:

I would personally go this route, as it's more elegant than duplicating your user password hashes (hopefully you're not storing the passwords themselves) in a separate text file, and creating a new authentication system seems like reinventing the wheel.

share|improve this answer
mod_auth_external was exactly what I wanted. Thank you! – John Peter Thompson Garcés Apr 20 '12 at 17:52

You can use .htaccess to limit access to certain directories.

You need to create a htpasswd file which you refer to from the .htaccess file

Python: there seems to be a library that can handle htpasswd files:

More about python and htpasswd:

I'm not familiar with python, and I can't give you a complete solution. I think however that it's possible, and probably not too complicated if you're familiar with python, with a bit of googling.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.