Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions cmscommon/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"""Utilities dealing with encryption and randomness."""

import binascii
import hmac
import random
from string import ascii_lowercase

Expand Down Expand Up @@ -190,15 +191,15 @@ def validate_password(authentication: str, password: str) -> bool:

"""
method, payload = parse_authentication(authentication)
password_bytes = password.encode("utf-8")
payload_bytes = payload.encode("utf-8")
if method == "bcrypt":
password_bytes = password.encode("utf-8")
payload_bytes = payload.encode("utf-8")
try:
return bcrypt.hashpw(password_bytes, payload_bytes) == payload_bytes
return bcrypt.checkpw(password_bytes, payload_bytes)
except ValueError:
return False
elif method == "plaintext":
return payload == password
return hmac.compare_digest(password_bytes, payload_bytes)
else:
raise ValueError("Authentication method not known.")

Expand Down