mod-auth-external and a program in the language of your choice that does as you want.

http://code.google.c...od-auth-external/