diff options
author | nOOb3167 <nOOb3167@gmail.com> | 2018-06-24 11:27:28 +0000 |
---|---|---|
committer | rubenwardy <rw@rubenwardy.com> | 2018-07-24 20:39:48 +0100 |
commit | 794bc8a018421e6d6ef8802f3c35fba9df7b7d17 (patch) | |
tree | 3a875e9dfb87c8ac68bbb3b9646cd9809963af27 /app/utils.py | |
parent | 34900222dc349fa884ea658993d1465c69b41011 (diff) | |
download | cheatdb-794bc8a018421e6d6ef8802f3c35fba9df7b7d17.tar.xz |
Add default password to admin user
Diffstat (limited to 'app/utils.py')
-rw-r--r-- | app/utils.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/app/utils.py b/app/utils.py index b2faa7a..dc65736 100644 --- a/app/utils.py +++ b/app/utils.py @@ -50,6 +50,25 @@ def doFileUpload(file, allowedExtensions, fileTypeName): file.save(os.path.join("app/public/uploads", filename)) return "/uploads/" + filename +def make_flask_user_password(plaintext_str): + # http://passlib.readthedocs.io/en/stable/modular_crypt_format.html + # http://passlib.readthedocs.io/en/stable/lib/passlib.hash.bcrypt.html#format-algorithm + # Flask_User stores passwords in the Modular Crypt Format. + # https://github.com/lingthio/Flask-User/blob/master/flask_user/user_manager__settings.py#L166 + # Note that Flask_User allows customizing password algorithms. + # USER_PASSLIB_CRYPTCONTEXT_SCHEMES defaults to bcrypt but if + # default changes or is customized, the code below needs adapting. + # Individual password values will look like: + # $2b$12$.az4S999Ztvy/wa3UdQvMOpcki1Qn6VYPXmEFMIdWQyYs7ULnH.JW + # $XX$RR$SSSSSSSSSSSSSSSSSSSSSSHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH + # $XX : Selects algorithm (2b is bcrypt). + # $RR : Selects bcrypt key expansion rounds (12 is 2**12 rounds). + # $SSS... : 22 chars of (random, per-password) salt + # HHH... : 31 remaining chars of password hash (note no dollar sign) + import bcrypt + plaintext = plaintext_str.encode("UTF-8") + password = bcrypt.hashpw(plaintext, bcrypt.gensalt()) + return password.decode("UTF-8") def _do_login_user(user, remember_me=False): def _call_or_get(v): |