-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackend.py
46 lines (35 loc) · 1.27 KB
/
backend.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import hashlib
import sqlite3
conn = sqlite3.connect("users.db")
c = conn.cursor()
admin = sqlite3.connect("watchman.db")
ac = admin.cursor()
def make_hashes(password):
return hashlib.sha256(str.encode(password)).hexdigest()
def check_hashes(password,hashed_text):
if make_hashes(password) == hashed_text:
return hashed_text
return False
def addUser(username,password):
c.execute('CREATE TABLE IF NOT EXISTS userstable(username TEXT,password TEXT)')
c.execute('INSERT INTO userstable(username,password) VALUES (?,?)',(username,password))
conn.commit()
def watchMan(username,password):
ac.execute('CREATE TABLE IF NOT EXISTS watchManTable(username TEXT,password TEXT)')
ac.execute('INSERT INTO watchManTable(username,password) VALUES (?,?)',(username,password))
admin.commit()
def inputUserData():
username = input("Enter Student Name ")
password = input("Enter Password")
hashed_passwd = make_hashes(password)
addUser(username,hashed_passwd)
def inputWatchManData():
username = input("Enter WatchMen Name")
password = input("Enter Password")
hashed_passwd = make_hashes(password)
watchMan(username,hashed_passwd)
userChoice = input("Press 1 For Creating User and 2 for watchman")
if userChoice == "1":
inputUserData()
elif userChoice == "2":
inputWatchManData()