Created
October 20, 2019 07:02
-
-
Save shimakaze-git/e4ea834921e09164d5a22159a8c4ace5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def make_password(password, salt=None, hasher='default'): | |
""" | |
Turn a plain-text password into a hash for database storage | |
Same as encode() but generate a new random salt. If password is None then | |
return a concatenation of UNUSABLE_PASSWORD_PREFIX and a random string, | |
which disallows logins. Additional random string reduces chances of gaining | |
access to staff or superuser accounts. See ticket #20079 for more info. | |
""" | |
if password is None: | |
return UNUSABLE_PASSWORD_PREFIX + get_random_string(UNUSABLE_PASSWORD_SUFFIX_LENGTH) | |
hasher = get_hasher(hasher) | |
salt = salt or hasher.salt() | |
return hasher.encode(password, salt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment