mirror of
https://github.com/django/django.git
synced 2025-08-12 21:09:13 +00:00
Use the stdlib's compare_digest for constant time comparisons when available
This commit is contained in:
parent
9fb95dfc9f
commit
58176dee88
@ -77,6 +77,10 @@ def get_random_string(length=12,
|
|||||||
return ''.join(random.choice(allowed_chars) for i in range(length))
|
return ''.join(random.choice(allowed_chars) for i in range(length))
|
||||||
|
|
||||||
|
|
||||||
|
if hasattr(hmac, "compare_digest"):
|
||||||
|
# Prefer the stdlib implementation, when available.
|
||||||
|
constant_time_compare = hmac.compare_digest
|
||||||
|
else:
|
||||||
def constant_time_compare(val1, val2):
|
def constant_time_compare(val1, val2):
|
||||||
"""
|
"""
|
||||||
Returns True if the two strings are equal, False otherwise.
|
Returns True if the two strings are equal, False otherwise.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user