16 lines
423 B
Python
16 lines
423 B
Python
import bcrypt
|
|
|
|
|
|
def hash_password(password: str) -> str:
|
|
raw = password.encode("utf-8")
|
|
# bcrypt limit is 72 bytes
|
|
digest = bcrypt.hashpw(raw[:72], bcrypt.gensalt())
|
|
return digest.decode("utf-8")
|
|
|
|
|
|
def verify_password(password: str, password_hash: str) -> bool:
|
|
try:
|
|
return bcrypt.checkpw(password.encode("utf-8")[:72], password_hash.encode("utf-8"))
|
|
except ValueError:
|
|
return False
|