Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13951

Password validation with pydantic

$
0
0

To avoid using if else loop, I did the following for adding a password validation in pydantic

    @field_validator("password")    def check_password(cls, value):        # convert the password to a string if it is not already        value = str(value)        # Check that the password meets the criteria        if len(value) < 8:            raise ValueError("Password must have at least 8 characters")        if not any(c.isupper() and c.islower() and c.isdigit() and c in string.punctuation for c in value):            raise ValueError("Password must have at least one uppercase letter, one lowercase letter, and one digit")        return value

But unfortunately that if not any condition is not working correctly, Can someone help me with fixing it?


Viewing all articles
Browse latest Browse all 13951

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>