Skip to content

Commit

Permalink
change the location of encode utf8
Browse files Browse the repository at this point in the history
  • Loading branch information
yangzhaofeng committed Nov 22, 2020
1 parent 1d29d15 commit a4fe489
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()


Expand Down
4 changes: 2 additions & 2 deletions app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit a4fe489

Please sign in to comment.