Refactoring server login code