Refactored password policy code