Skip to content

Commit 3070e8f

Browse files
committed
Properly force bytes or str for bcrypt on Python3
1 parent 9012833 commit 3070e8f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

django/contrib/auth/hashers.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from django.test.signals import setting_changed
1010
from django.utils import importlib
1111
from django.utils.datastructures import SortedDict
12-
from django.utils.encoding import force_bytes, force_str
12+
from django.utils.encoding import force_bytes, force_str, force_text
1313
from django.core.exceptions import ImproperlyConfigured
1414
from django.utils.crypto import (
1515
pbkdf2, constant_time_compare, get_random_string)
@@ -291,7 +291,7 @@ def encode(self, password, salt):
291291
password = force_bytes(password)
292292

293293
data = bcrypt.hashpw(password, salt)
294-
return "%s$%s" % (self.algorithm, data)
294+
return "%s$%s" % (self.algorithm, force_text(data))
295295

296296
def verify(self, password, encoded):
297297
algorithm, data = encoded.split('$', 1)
@@ -307,6 +307,9 @@ def verify(self, password, encoded):
307307
else:
308308
password = force_bytes(password)
309309

310+
# Ensure that our data is a bytestring
311+
data = force_bytes(data)
312+
310313
return constant_time_compare(data, bcrypt.hashpw(password, data))
311314

312315
def safe_summary(self, encoded):

0 commit comments

Comments
 (0)