refactoring server authentication codes