pydantic / pydantic-extra-types

Extra Pydantic types.
MIT License
181 stars 48 forks source link

chore(feat): Support Password as Type #17

Open yezz123 opened 1 year ago

yezz123 commented 1 year ago

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

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 commented 1 year ago

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