From b0765362b979f32fcec82f2caf90b3ef644da327 Mon Sep 17 00:00:00 2001 From: Paul Marillonnet Date: Wed, 16 Oct 2019 14:33:16 +0200 Subject: [PATCH] python3: 'hex' is not an encoding anymore (#36995) --- src/authentic2/hashers.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/authentic2/hashers.py b/src/authentic2/hashers.py index d0183831e..1c864886b 100644 --- a/src/authentic2/hashers.py +++ b/src/authentic2/hashers.py @@ -17,7 +17,7 @@ import hashlib import math import base64 -from binascii import hexlify +from binascii import hexlify, unhexlify from collections import OrderedDict from django.contrib.auth import hashers @@ -180,17 +180,17 @@ def olap_password_to_dj(password): class OpenLDAPPasswordHasher(CommonPasswordHasher): def encode(self, password, salt): assert password - assert '$' not in salt + assert b'$' not in salt hash = self.digest(force_bytes(password + salt)).hexdigest() salt = force_text(hexlify(salt), encoding='ascii') return "%s$%s$%s" % (self.algorithm, salt, hash) def verify(self, password, encoded): algorithm, salt, hash = encoded.split('$', 2) - hash = hash.decode('hex') - salt = salt.decode('hex') + hash = unhexlify(hash) + salt = unhexlify(salt) assert algorithm == self.algorithm - encoded_2 = self.encode(password, salt) + encoded_2 = self.encode(force_bytes(password), salt) return constant_time_compare(encoded, encoded_2) @@ -238,7 +238,7 @@ class JoomlaPasswordHasher(CommonPasswordHasher): def verify(self, password, encoded): algorithm, subalgo, salt, hash = encoded.split('$', 3) - salt = salt.decode('hex') + salt = unhexlify(salt) if algorithm != self.algorithm: raise ValueError('not a joomla encoded password') encoded_2 = self.encode(password, salt)