-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
53 lines (43 loc) · 1.64 KB
/
model.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import cryptocode
import getpass
import json
class ModelNeverAgainForgetYourPasswords:
def __init__(self):
self.__data = self.__open_data()
self.__testing_pw = "devdiogenes.com"
def __open_data(self): #Open a data file if it exist, create if don't
try:
json_file = open("Passwords.json", "r")
json_data = json.loads(json_file.read())
json_file.close()
return json_data
except:
self.__data = {}
self.__write_data()
return {}
def __write_data(self):
open("Passwords.json", "w").write(json.dumps(self.__data, indent = 4))
def _check_register(self):
if "master_pw" in self.__data.keys():
return True
else:
return False
def _register(self, master_pw):
encrypted_master_pw = cryptocode.encrypt(self.__testing_pw, master_pw)
self.__data["master_pw"] = encrypted_master_pw
self.__write_data()
def _try_login(self, master_pw):
decrypted_master_pw = cryptocode.decrypt(self.__data["master_pw"], master_pw)
if decrypted_master_pw == self.__testing_pw:
return master_pw
else:
return False
def _add_pass(self, encrypted_pw, description):
if "passwords" not in self.__data.keys():
self.__data["passwords"] = {}
self.__data["passwords"][description] = encrypted_pw
self.__write_data()
def _get_passwords(self):
if "passwords" not in self.__data.keys():
self.__data["passwords"] = {}
return self.__data["passwords"]