From 8812444da0d1c39be3b9a41b3113f8352d5ad7e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 28 Jul 2020 13:40:51 +0200 Subject: [PATCH] fix encoding of credentials --- mandayejs/mandaye/models.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mandayejs/mandaye/models.py b/mandayejs/mandaye/models.py index 1a79788..37a30de 100644 --- a/mandayejs/mandaye/models.py +++ b/mandayejs/mandaye/models.py @@ -22,7 +22,7 @@ from Crypto import Random from django.db import models from django.conf import settings from django.utils.translation import ugettext_lazy as _ -from django.utils.encoding import force_bytes +from django.utils.encoding import force_bytes, force_text from jsonfield import JSONField @@ -58,10 +58,11 @@ class UserCredentials(models.Model): password_field_name = get_password_field() iv = Random.get_random_bytes(16) cipher = self._get_cipher(iv) - password = self.locators.get(password_field_name, '').encode('utf-8') + password = force_bytes(self.locators.get(password_field_name, '')) crypted = cipher.encrypt(password) - self.locators[password_field_name] = '%s$%s' % (base64.b64encode(iv), - base64.b64encode(crypted)) + self.locators[password_field_name] = '%s$%s' % ( + force_text(base64.b64encode(iv)), + force_text(base64.b64encode(crypted))) return self.locators def decrypt(self,):