forked from UTSAVS26/PyVerse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.py
More file actions
24 lines (19 loc) · 654 Bytes
/
Copy pathauth.py
File metadata and controls
24 lines (19 loc) · 654 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import os
import base64
import hashlib
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from cryptography.hazmat.primitives import hashes
KEY_SIZE = 32
import hmac
def verify_token(provided_token: str, expected_token: str) -> bool:
return hmac.compare_digest(provided_token.encode(), expected_token.encode())
from cryptography.hazmat.backends import default_backend
def derive_key(password: str, salt: bytes) -> bytes:
kdf = PBKDF2HMAC(
algorithm=hashes.SHA256(),
length=KEY_SIZE,
salt=salt,
iterations=100_000,
backend=default_backend()
)
return kdf.derive(password.encode())