mirror of
https://github.com/minetest/contentdb.git
synced 2024-12-22 22:12:24 +01:00
Add default password to admin user
This commit is contained in:
parent
34900222dc
commit
794bc8a018
19
app/utils.py
19
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):
|
||||
|
3
setup.py
3
setup.py
@ -23,6 +23,7 @@ if not "FLASK_CONFIG" in os.environ:
|
||||
test_data = len(sys.argv) >= 2 and sys.argv[1].strip() == "-t"
|
||||
|
||||
from app.models import *
|
||||
from app.utils import make_flask_user_password
|
||||
|
||||
def defineDummyData(licenses, tags, ruben):
|
||||
ez = User("Shara")
|
||||
@ -342,6 +343,8 @@ db.create_all()
|
||||
print("Filling database...")
|
||||
|
||||
ruben = User("rubenwardy")
|
||||
ruben.active = True
|
||||
ruben.password = make_flask_user_password("tuckfrump")
|
||||
ruben.github_username = "rubenwardy"
|
||||
ruben.forums_username = "rubenwardy"
|
||||
ruben.rank = UserRank.ADMIN
|
||||
|
Loading…
Reference in New Issue
Block a user