refactor login checking process