diff options
Diffstat (limited to 'authentication/utils.py')
| -rw-r--r-- | authentication/utils.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/authentication/utils.py b/authentication/utils.py index f383969..4f19bc3 100644 --- a/authentication/utils.py +++ b/authentication/utils.py | |||
| @@ -1,6 +1,9 @@ | |||
| 1 | import base64 | 1 | import base64 |
| 2 | import hashlib | 2 | import hashlib |
| 3 | from urllib.parse import urlencode | ||
| 4 | |||
| 3 | import bcrypt | 5 | import bcrypt |
| 6 | from fastapi import FastAPI | ||
| 4 | 7 | ||
| 5 | 8 | ||
| 6 | def bcrypt_sha256_hash(password: str) -> str: | 9 | def bcrypt_sha256_hash(password: str) -> str: |
| @@ -13,3 +16,10 @@ def bcrypt_sha256_verify(password: str, hashed: str) -> bool: | |||
| 13 | digest = hashlib.sha256(password.encode("utf-8")).digest() | 16 | digest = hashlib.sha256(password.encode("utf-8")).digest() |
| 14 | encoded = base64.b64encode(digest) | 17 | encoded = base64.b64encode(digest) |
| 15 | return bcrypt.checkpw(encoded, hashed.encode('utf-8')) | 18 | return bcrypt.checkpw(encoded, hashed.encode('utf-8')) |
| 19 | |||
| 20 | |||
| 21 | def get_url_path_with_query(app: FastAPI, name: str, params: dict | None = None, /, **path_params: str): | ||
| 22 | base = app.url_path_for(name, **path_params) | ||
| 23 | return base + '?' + urlencode(params) if params is not None else base | ||
| 24 | |||
| 25 | |||
