Files
zulip/zerver/lib/initial_password.py
Eklavya Sharma 6097f6eed5 zerver/lib/initial_password.py: Encode return value.
zerver.lib.initial_password.initial_password is supposed to return an
Optional[text_type], but it returns an Optional[binary_type] instead.
Encode the return value to make sure it returns an Optional[text_type].
2016-06-18 16:41:40 -07:00

24 lines
708 B
Python

from __future__ import absolute_import
from django.conf import settings
import hashlib
import base64
from typing import Optional
from six import text_type
def initial_password(email):
# type: (text_type) -> Optional[text_type]
"""Given an email address, returns the initial password for that account, as
created by populate_db."""
if settings.INITIAL_PASSWORD_SALT is not None:
encoded_key = (settings.INITIAL_PASSWORD_SALT + email).encode("utf-8")
digest = hashlib.sha256(encoded_key).digest()
return base64.b64encode(digest)[:16].decode('utf-8')
else:
# None as a password for a user tells Django to set an unusable password
return None