pydantic-extra-types icon indicating copy to clipboard operation
pydantic-extra-types copied to clipboard

chore(feat): Support Password as Type

Open yezz123 opened this issue 2 years ago • 1 comments

As we have this point before https://github.com/pydantic/pydantic/issues/5012

  • password type, can mostly used strip_whitespace and min_length, but also integrate with https://github.com/dwolfhub/zxcvbn-python ???
from pydantic import BaseModel
from pydantic_extra_types import PasswordStr

class Data(BaseModel):
    password: PasswordStr

    def __init__(self, **data: Any):
        super().__init__(**data)

    def __repr__(self) -> str:
        return f'Data(password={self.password})'


def test_password():
    # Test password strength calculation
    d = Data(password='weakpassword')
    assert d.password.strength['score'] < 3

    d = Data(password='strongpassword123')
    assert d.password.strength['score'] >= 1

yezz123 avatar Feb 20 '23 20:02 yezz123

@samuelcolvin This one also works fine locally you can test it before we merge it

yezz123 avatar Mar 09 '23 20:03 yezz123