For OS level auth, you'd want to use sssd, which will handle most failure conditions:
https://fedorahosted.org/sssd/ https://wiki.ubuntu.com/Enterprise/Authentication/sssd
https://fedorahosted.org/sssd/ https://wiki.ubuntu.com/Enterprise/Authentication/sssd