Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(feat): Support Password as Type #17

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

chore(feat): Support Password as Type #17

wants to merge 2 commits into from

Conversation

yezz123
Copy link
Collaborator

@yezz123 yezz123 commented Feb 20, 2023

As we have this point before pydantic/pydantic#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
Copy link
Collaborator Author

yezz123 commented Mar 9, 2023

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

Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should change to become an annotation type, (see UuidVersion for an example in pydantic) so it can be applied to str, bytes or the secret types.

)

@classmethod
def validate(cls, __input_value: str, **_kwargs: Any) -> 'PasswordStr':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the signature has changed, this won't work with pydantic main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants