Refactoring of login's logic.