-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdata.py
More file actions
73 lines (64 loc) · 2.25 KB
/
data.py
File metadata and controls
73 lines (64 loc) · 2.25 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
import encryption
import pickle
import login
class User:
'''for maintaing a instance of each user'''
def __init__(self, username, password):
self.username = username
self.password = password
self.key = login.verify(username, password)
def usercheck(self):
'''Checks if the username and the password matches'''
if not self.key:
return False
else:
return True
def get_data(self):
file = open("data.txt", 'rb')
dictionary = pickle.load(file)
file.close()
data = dictionary[self.username]
print("username---password---sitename")
for i in data:
for j in i:
unencoded = encryption.decrypter(j, self.key)
print(unencoded.decode(), end="---")
print("")
def add_data(self, username1, password1, sitename):
username1 = username1.encode()
password1 = password1.encode()
sitename = sitename.encode()
file = open('data.txt', 'rb')
dictionary = pickle.load(file)
file.close()
data = dictionary[self.username]
entry = (encryption.encrypter(username1, self.key), encryption.encrypter(password1, self.key),
encryption.encrypter(sitename, self.key))
data.append(entry)
dictionary[self.username] = data
file = open('data.txt', 'wb')
pickle.dump(dictionary, file)
file.close()
def remove_data(self, sitename):
file = open('data.txt', 'rb')
dictionary = pickle.load(file)
file.close()
data = dictionary[self.username]
count = 0
while count < len(data):
if encryption.decrypter(data[count][2], self.key) == sitename.encode():
data.pop(count)
else:
print("site doesnt exist")
count += 1
dictionary[self.username] = data
file = open('data.txt', 'wb')
pickle.dump(dictionary, file)
file.close()
def file_checker():
try:
file = open("data.txt", "rb")
except FileNotFoundError:
file = open('data.txt', 'wb')
pickle.dump({}, file)
file.close()