PAM - Pluggable Authentication Module(s)
You could have a field day scripting whatever authentication scheme you please.
pam_script installation and examples:
DO NOT screw with '/etc/pam.d/login' like the examples. One mess up and you can't login to your machine anymore. If this happens reboot your machine with: init=/bin/bash on the kernel command line.