s365b.auth.passwords¶
Password and recovery-code hashing (Argon2id) and password policy.
Attributes¶
Exceptions¶
Raised when a password does not meet the policy. |
Functions¶
|
Check a new password against the policy. |
|
Hash a password or recovery code. |
|
Check a password against a stored hash in constant-ish time. |
|
Create one-time recovery codes for a break-glass account. |
|
Check a recovery code and consume it. |
|
|
|
|
|
|
|
|
Module Contents¶
- exception s365b.auth.passwords.PasswordPolicyError[source]¶
Bases:
ValueErrorRaised when a password does not meet the policy.
- s365b.auth.passwords.check_policy(password: str, username: str) None[source]¶
Check a new password against the policy.
Policy: at least 14 characters, not containing the username. Length is what matters for an account that is used rarely and written down in a safe; no composition rules.
- Parameters:
password – Proposed password.
username – The account’s username.
- Raises:
PasswordPolicyError – With a message suitable for the user.
- s365b.auth.passwords.hash_password(password: str) str[source]¶
Hash a password or recovery code.
- Parameters:
password – Plaintext.
- Returns:
Argon2id hash string.
- s365b.auth.passwords.verify_password(stored_hash: str | None, password: str) bool[source]¶
Check a password against a stored hash in constant-ish time.
- Parameters:
stored_hash – Hash from the database;
Noneif the user has none (a dummy hash is checked so timing does not differ).password – Plaintext to check.
- Returns:
True if it matches.
- s365b.auth.passwords.generate_recovery_codes() tuple[list[str], list[str]][source]¶
Create one-time recovery codes for a break-glass account.
- Returns:
codes to show the user once, and hashes to store.
- Return type:
(codes, hashes)
- s365b.auth.passwords.use_recovery_code(hashes: list[str], code: str) list[str] | None[source]¶
Check a recovery code and consume it.
- Parameters:
hashes – Stored hashes of unused codes.
code – Code entered by the user.
- Returns:
The remaining hashes if the code was valid, else
None.
- async s365b.auth.passwords.hash_password_async(password: str) str[source]¶
hash_password()in a worker thread (seeHASH_SLOTS).- Parameters:
password – Plaintext.
- Returns:
Argon2id hash string.
- async s365b.auth.passwords.verify_password_async(stored_hash: str | None, password: str) bool[source]¶
verify_password()in a worker thread (seeHASH_SLOTS).- Parameters:
stored_hash – Hash from the database, or
None.password – Plaintext to check.
- Returns:
True if it matches.
- async s365b.auth.passwords.generate_recovery_codes_async() tuple[list[str], list[str]][source]¶
generate_recovery_codes()in a worker thread.- Returns:
(codes, hashes).
- async s365b.auth.passwords.use_recovery_code_async(hashes: list[str], code: str) list[str] | None[source]¶
use_recovery_code()in a worker thread.- Parameters:
hashes – Stored hashes of unused codes.
code – Code entered by the user.
- Returns:
The remaining hashes if the code was valid, else
None.