Extract loop login out to a method to make it more testable.