Fix logic to correctly perform login function