Refactor the function validatePassword in order to make it more
adaptable