Improve password validation logic