Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a script to create a user #617

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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='test@test.bbs')

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()