diff options
Diffstat (limited to 'authentication/utils.py')
| -rw-r--r-- | authentication/utils.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/authentication/utils.py b/authentication/utils.py new file mode 100644 index 0000000..f383969 --- /dev/null +++ b/authentication/utils.py | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | import base64 | ||
| 2 | import hashlib | ||
| 3 | import bcrypt | ||
| 4 | |||
| 5 | |||
| 6 | def bcrypt_sha256_hash(password: str) -> str: | ||
| 7 | digest = hashlib.sha256(password.encode("utf-8")).digest() | ||
| 8 | encoded = base64.b64encode(digest) | ||
| 9 | return bcrypt.hashpw(encoded, bcrypt.gensalt()).decode("utf-8") | ||
| 10 | |||
| 11 | |||
| 12 | def bcrypt_sha256_verify(password: str, hashed: str) -> bool: | ||
| 13 | digest = hashlib.sha256(password.encode("utf-8")).digest() | ||
| 14 | encoded = base64.b64encode(digest) | ||
| 15 | return bcrypt.checkpw(encoded, hashed.encode('utf-8')) | ||
