Refactored login validation