summaryrefslogtreecommitdiffstats
path: root/authentication/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'authentication/utils.py')
-rw-r--r--authentication/utils.py15
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 @@
1import base64
2import hashlib
3import bcrypt
4
5
6def 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
12def 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'))