This is a topic that has interested me as well. Although I
havent had the time to fully explore it, I think you may want
to start by looking into apache::htpasswd.
It looks like it provides a good deal of the abilities that you're
looking for. Plus, I believe its written by one of our own.
You may also want to read through this which seems to
provide some external info on the topic you're interested in.