extract login logic