-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmydb.py
36 lines (27 loc) · 873 Bytes
/
mydb.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
import json
class Database:
# to insert data in to json
def add_data(self,name,email,password):
with open('db.json','r') as rf:
database = json.load(rf)
if email in database:
return 0
else:
if email == '':
return 0
else:
database[email] = [name,password]
with open('db.json','w') as wf:
json.dump(database,wf)
return 1
# to check user details in json
def search(self,email,password):
with open('db.json','r') as rf:
database = json.load(rf)
if email in database:
if database[email][1] == password:
return 1
else:
0
else:
0