-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.py
32 lines (23 loc) · 798 Bytes
/
db.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
import json
class Database:
def insert(self,name,email,password):
with open('users.json','r') as rf:
users = json.load(rf)
if email not in users:
users[email] = [name,password]
else:
return 0
with open('users.json','w') as wf:
json.dump(users,wf,indent=4)
return 1
def search(self,email,password):
with open('users.json','r') as rf:
users = json.load(rf)
if email in users and users[email][1] == password:
return 1
else:
return 0
def db_return_name(self,email):
with open('users.json','r') as rf:
users = json.load(rf)
return users[email][0]