9
9
from django .test .signals import setting_changed
10
10
from django .utils import importlib
11
11
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
13
13
from django .core .exceptions import ImproperlyConfigured
14
14
from django .utils .crypto import (
15
15
pbkdf2 , constant_time_compare , get_random_string )
@@ -291,7 +291,7 @@ def encode(self, password, salt):
291
291
password = force_bytes (password )
292
292
293
293
data = bcrypt .hashpw (password , salt )
294
- return "%s$%s" % (self .algorithm , data )
294
+ return "%s$%s" % (self .algorithm , force_text ( data ) )
295
295
296
296
def verify (self , password , encoded ):
297
297
algorithm , data = encoded .split ('$' , 1 )
@@ -307,6 +307,9 @@ def verify(self, password, encoded):
307
307
else :
308
308
password = force_bytes (password )
309
309
310
+ # Ensure that our data is a bytestring
311
+ data = force_bytes (data )
312
+
310
313
return constant_time_compare (data , bcrypt .hashpw (password , data ))
311
314
312
315
def safe_summary (self , encoded ):
0 commit comments