Factor out password validation
Refactoring login code