Skip to content

Commit

Permalink
Adds a script to create a user (#617)
Browse files Browse the repository at this point in the history
  • Loading branch information
paladine authored Jan 11, 2024
1 parent afb16cf commit e7ce7d5
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions scripts/create_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/python3

import argparse
import base64
import hashlib
import os
import sqlite3
import sys

def _create_parser():
parser = argparse.ArgumentParser(description='Create MBBSEmu user accounts.')
parser.add_argument('--username', help='Username to create', required=True)
parser.add_argument('--password', help='Password to use', required=True)
parser.add_argument('--keys', help='Account keys to add to the new account', action='append', default=['NORMAL','PAYING'])
parser.add_argument('--email', help='Email address to use', default='[email protected]')

return parser.parse_args()

def _make_password_hash(password, salt_bytes):
m = hashlib.sha512()
m.update(password.encode(encoding = 'UTF-8', errors = 'strict'))
m.update(salt_bytes)
return m.digest()

def _main():
args = _create_parser()

conn = sqlite3.connect('mbbs.db')

passwordSaltBytes=os.urandom(32)
passwordHashBytes=_make_password_hash(args.password, passwordSaltBytes)

cur = conn.cursor()
t = (args.username, str(base64.b64encode(passwordHashBytes), encoding='utf-8'), str(base64.b64encode(passwordSaltBytes), encoding='utf-8'), args.email)
cur.execute('INSERT INTO Accounts (userName, passwordHash, passwordSalt, email, createDate, updateDate) VALUES (?,?,?,?, datetime(\'now\'), datetime(\'now\'))', t)
conn.commit()

account_id = cur.lastrowid

for user_key in args.keys:
t = (account_id, user_key)
cur.execute('INSERT INTO AccountKeys (accountId, accountKey, createDate, updateDate) VALUES (?,?,datetime(\'now\'), datetime(\'now\'))', t)
conn.commit()

if __name__ == '__main__':
_main()

0 comments on commit e7ce7d5

Please sign in to comment.