-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauth.py
More file actions
87 lines (71 loc) · 2.52 KB
/
Copy pathauth.py
File metadata and controls
87 lines (71 loc) · 2.52 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import json
from secrets import token_urlsafe
from pathlib import Path
import os
import getpass
import sys
if sys.platform == "darwin":
if not os.path.exists("/Library/Caches/.menousdb"):
os.mkdir("/Library/Caches/.menousdb")
if not os.path.exists("/Library/Caches/.menousdb/authdata"):
os.mkdir("/Library/Caches/.menousdb/authdata")
path = "/Library/Caches/.menousdb/authdata"
elif sys.platform == "win32":
if not os.path.exists(os.getenv("APPDATA")+"\\MenoudDb"):
os.mkdir(os.getenv("APPDATA")+"\\MenoudDb")
if not os.path.exists(os.getenv("APPDATA")+"\\MenoudDb"+"\\authdata"):
os.mkdir(os.getenv("APPDATA")+"\\MenoudDb\\authdata")
path = os.getenv("APPDATA")+"\\MenoudDb"+"\\authdata"
def check_key(key):
with open(path+'/keys.json') as file:
data = json.load(file)
if key in data:
return True
else:
return False
def generate_key():
with open(path+'/keys.json') as file:
data = json.load(file)
key = token_urlsafe(16)
with open(path+'/keys.json', 'w') as file:
data.append(key)
json.dump(data, file, indent=4)
return key
def login(username, password):
if not os.path.exists(path + "/login.json"):
with open(path + "/login.json", 'w') as file:
file.dump({})
return 'Sign Up Required! Please contact Administrator'
with open(path + "/login.json", 'r') as file:
data = json.load(file)
for i in data:
if i == username and data[i][0] == password:
return True
return False
def getUserKey(username):
with open(path + "/login.json", 'r') as file:
data = json.load(file)
for i in data:
if i == username:
return data[i][0]
def signup():
with open(path + "/login.json", "r") as file:
data = json.load(file)
while True:
print("~~~~~~~~~~~~~~~~~~~~~~WELCOME TO MENOUSDB~~~~~~~~~~~~~~~~~~~~~~~~~~~")
uname = input("ENTER A USERNAME: ")
pw = getpass.getpass("ENTER PASSWORD: ")
confirm = getpass.getpass("RE-ENTER PASSWORD: ")
if pw == confirm:
data[uname] = [pw, generate_key()]
with open(path + "/login.json", "w") as file:
json.dump(data, file, indent=4)
exit()
else:
print("ERROR! PASSWORDS DO NOT MATCH! TRY AGAIN!\n")
def checksignup():
with open(path + "/login.json", "r") as file:
data = json.load(file)
if data == {}:
signup()
checksignup()