-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add password fields to schema * add password related config options * add ability to set password * add hidden fields * password prompt at login * rearchitect login to use callbacks * add password check to stockterminal * update tillweb * handle hotkeypress() in password prompt * force setting password on login if required * add password-only logon * update last seen when logging in with password * show user ID in edit dialogs * clear last_successful_login when tokens are (re)assigned * allow users to remove their own passwords
- Loading branch information
1 parent
2ce7090
commit 6f1bb3b
Showing
11 changed files
with
536 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
"""Till password hashing and checking logic. | ||
This module provides functions to create 'password tuples' which take the format | ||
`algorithm$iterations$salt$hash_hex`. | ||
""" | ||
|
||
import secrets | ||
import hashlib | ||
|
||
|
||
def compute_password_tuple(password): | ||
"""Computes the password tuple for storage in the database. | ||
Returns a string in the format `algorithm$iterations$salt$hash_hex`. | ||
""" | ||
iterations = 500_000 | ||
salt = secrets.token_hex(16) | ||
hash = compute_pbkdf2(password, salt, iterations) | ||
return f"pbkdf2${iterations}${salt}${hash}" | ||
|
||
|
||
def compute_pbkdf2(value, salt, iterations): | ||
"""Computes t he PBKDF2 hash for a value given a salt and number of | ||
iterations. | ||
""" | ||
hash = hashlib.pbkdf2_hmac("sha256", bytes(value, "utf-8"), | ||
bytes(salt, "utf-8"), iterations) | ||
return hash.hex() | ||
|
||
|
||
def check_password(password, tuple): | ||
"""Checks a password against a tuple. | ||
The tuple must be in the format `algorithm$iterations$salt$hash_hex`. | ||
Malformed values will raise an exception. | ||
""" | ||
elems = tuple.split("$") | ||
if len(elems) != 4: | ||
raise Exception("Invalid password tuple presented (len(elems) != 4).") | ||
|
||
algo = elems[0] | ||
iterations = int(elems[1]) | ||
salt = elems[2] | ||
hash = elems[3] | ||
|
||
if algo == 'pbkdf2': | ||
return compute_pbkdf2(password, salt, iterations) == hash | ||
else: | ||
raise Exception("Unsupported password algorithm: " + algo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.