Skip to content

Commit

Permalink
Add examples docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
frankie567 committed Feb 12, 2024
1 parent 250eef6 commit 6132d72
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pwdlib/_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ def recommended(cls) -> "PasswordHash":
Returns a PasswordHash instance with recommended hashers.
Currently, the hasher is Argon2 with default parameters.
Examples:
>>> password_hash = PasswordHash.recommended()
>>> hash = password_hash.hash("herminetincture")
>>> password_hash.verify(hash, "herminetincture")
True
"""
from .hashers.argon2 import Argon2Hasher

Expand All @@ -47,6 +53,9 @@ def hash(
Returns:
The hashed password.
Examples:
>>> hash = password_hash.hash("herminetincture")
"""
return self.current_hasher.hash(password, salt=salt)

Expand All @@ -65,6 +74,13 @@ def verify(
Raises:
exceptions.UnknownHashError: If the hash is not recognized by any of the hashers.
Examples:
>>> password_hash.verify(hash, "herminetincture")
True
>>> password_hash.verify(hash, "INVALID_PASSWORD")
False
"""
for hasher in self.hashers:
if hasher.identify(hash):
Expand All @@ -87,6 +103,9 @@ def verify_and_update(
Raises:
exceptions.UnknownHashError: If the hash is not recognized by any of the hashers.
Examples:
>>> valid, updated_hash = password_hash.verify_and_update(hash, "herminetincture")
"""
for hasher in self.hashers:
if hasher.identify(hash):
Expand Down

0 comments on commit 6132d72

Please sign in to comment.