Skip to content

Commit 9846c7b

Browse files
authored
Improved password verification to use constant-time comparison
1 parent e04eb0b commit 9846c7b

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

bazarr/utilities/helper.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import logging
55
import hashlib
6+
import hmac
67

78
from charset_normalizer import detect
89
from bs4 import UnicodeDammit
@@ -16,7 +17,8 @@ def check_credentials(user, pw, request, log_success=True):
1617
ip_addr = forwarded_for_ip_addr or real_ip_addr or request.remote_addr
1718
username = settings.auth.username
1819
password = settings.auth.password
19-
if hashlib.md5(f"{pw}".encode('utf-8')).hexdigest() == password and user == username:
20+
submitted_hash = hashlib.md5(f"{pw}".encode('utf-8')).hexdigest()
21+
if hmac.compare_digest(submitted_hash, str(password or '')) and user == username:
2022
if log_success:
2123
logging.info(f'Successful authentication from {ip_addr} for user {user}')
2224
return True

0 commit comments

Comments
 (0)