forked from Masood-Zain/WebPaisa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.py
32 lines (25 loc) · 891 Bytes
/
database.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 hashlib
import json
import requests
DATABASE_URL = "https://gist.githubusercontent.com/Basicprogrammer10/11df12fc82f0b01c65c03db8ce23cccf/raw/17b9c92104d5233572d8e8492e9828805b834c4b/webpaisa-data.json"
class Database:
def __init__(self):
raw_data = requests.get(DATABASE_URL).text
self.data = json.loads(raw_data)
def raw(self):
return self.data
def get_user(self, username):
for user in self.data["users"]:
if user["username"] == username:
return user
return None
def login(self, username, password):
user = self.get_user(username)
if user is None:
return False
hashGen = hashlib.sha512()
hashGen.update(password.encode('utf-8'))
hash = hashGen.hexdigest()
if hash == user["password"]:
return True
return False