Password hashing: hash a password to a PHC string, verify one, and check for a rehash.
Functions#
hash#
hash(password) -> Effect[str, CryptoError]Hashes password with the configured algorithm, a 16-byte random
salt and a 32-byte output, returning the PHC string.
| Parameter | Type | Description |
|---|---|---|
password | str | Redacted[str] |
Returns Effect[str, CryptoError]
def hash(self, password: str | Redacted[str]) -> Effect[str, CryptoError]:
"""Hashes ``password`` with the configured algorithm, a 16-byte random
salt and a 32-byte output, returning the PHC string."""
...verify#
verify(password, hash) -> Effect[bool, CryptoError]Checks password against a stored PHC string, with the algorithm
and salt it records. A wrong password is False; a malformed stored
hash fails with an InvalidArgument reason.
| Parameter | Type | Description |
|---|---|---|
password | str | Redacted[str] | |
hash | str |
Returns Effect[bool, CryptoError]
def verify(self, password: str | Redacted[str], hash: str) -> Effect[bool, CryptoError]:
"""Checks ``password`` against a stored PHC string, with the algorithm
and salt it records. A wrong password is ``False``; a malformed stored
hash fails with an ``InvalidArgument`` reason."""
...needs_rehash#
needs_rehash(hash) -> Effect[bool, CryptoError]Whether a stored PHC string differs from what hash would make
now: another algorithm or cost, or a salt or output length other than
16 and 32 bytes. Rehash the password after a successful verify
when it does.
| Parameter | Type | Description |
|---|---|---|
hash | str |
Returns Effect[bool, CryptoError]
def needs_rehash(self, hash: str) -> Effect[bool, CryptoError]:
"""Whether a stored PHC string differs from what ``hash`` would make
now: another algorithm or cost, or a salt or output length other than
16 and 32 bytes. Rehash the password after a successful ``verify``
when it does."""
...