Working auth system, if a bit ugly.