-
Notifications
You must be signed in to change notification settings - Fork 0
/
mydb.py
32 lines (24 loc) · 905 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
import json
class database:
def add_data(self,name,email,password):
"""Add data of user into json file if not exists else not."""
with open('db.json','r') as rf:
database = json.load(rf)
if email in database:
return 0
else:
database[email] = [name,password]
with open('db.json','w') as wf:
json.dump(database,wf)
return 1
def search(self,email,password):
"""Checks whether email and password given by the user is correct or not."""
with open('db.json','r') as rf:
database = json.load(rf)
if email in database:
if database[email][1] == password:
return 1
else:
return 0
else:
return 0