main login logic