if len(password) < 8:
    raise AppropriateError('password is too short')
if any(passChar not in hardCodedSetOfAllowedCharacters for passChar in password
    ):
    raise AppropriateError('password contains illegal characters')
return password
How to test a regex password in Python?