-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddUser.py
More file actions
23 lines (20 loc) · 776 Bytes
/
addUser.py
File metadata and controls
23 lines (20 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import sqlite3
import hashlib
import os
import getpass
def hash(password:'ReadeableBuffer', salt:'ReadeableBuffer') -> bytes:
key = hashlib.pbkdf2_hmac('sha256', password.encode('utf-8'), salt, 100000)
return key
def addUser(login:str, password:str, auth:int) -> None:
salt = os.urandom(32)
password = hash(password, salt)
conn = sqlite3.connect('main.db')
cur = conn.cursor()
cur.execute('INSERT INTO users VALUES (?, ?, ?, ?)', (login, password, salt, auth))
conn.commit()
if __name__ == '__main__':
print('Welcome to the backend user adding utility.')
login = input('New user login:')
password = getpass.getpass("New user password:")
auth = input('Input new user authority level:')
addUser(login, password, int(auth))