Improve password validation logic.

Resolves #233, Closes #239.