From 8f0090473fb9277686967cc1f8109ebae0c38ef5 Mon Sep 17 00:00:00 2001 From: Zhaofeng Yang Date: Mon, 23 Nov 2020 00:45:31 +0800 Subject: [PATCH] change the location of encode utf8 --- app/models.py | 4 ++-- app/utils.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models.py b/app/models.py index 7275304..5366e66 100644 --- a/app/models.py +++ b/app/models.py @@ -68,7 +68,7 @@ def get_expiration_by_email(cls, email): def add(cls, email, password, expiration): account = cls.get_account_by_email(email) if not account: - account = cls(email, hash_passwd(password)) + account = cls(email, hash_passwd(password.encode('utf-8'))) account.save() if not Group.get_group_by_email(email): group = Group(email) @@ -107,7 +107,7 @@ def changepass(cls, email, newpass): if not account: raise Exception('account not found') else: - account.value = hash_passwd(newpass) + account.value = hash_passwd(newpass.encode('utf-8')) account.save() diff --git a/app/utils.py b/app/utils.py index 44027fd..9319432 100644 --- a/app/utils.py +++ b/app/utils.py @@ -12,8 +12,8 @@ def hash_passwd_with_salt(passwd, salt): return hash_clean def hash_passwd(passwd): - salt = random_string(8) - return hash_passwd_with_salt(passwd.encode('utf-8'),salt.encode('utf-8')) + salt = random_string(8).encode('utf-8') + return hash_passwd_with_salt(passwd,salt) def random_string(N): return ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for i in range(N))