-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmydb.py
More file actions
23 lines (22 loc) · 711 Bytes
/
mydb.py
File metadata and controls
23 lines (22 loc) · 711 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 json
class Database:
def add_user(self, name, email, password):
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, indent=4)
return 1
def search_user(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:
return 0
else:
return 0