consolidated login logic