-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorage.py
More file actions
52 lines (43 loc) · 1.21 KB
/
storage.py
File metadata and controls
52 lines (43 loc) · 1.21 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
import json
import os
from encryption import encrypt_password, decrypt_password
DATA_FILE = "data.json"
def load_data():
if os.path.exists(DATA_FILE):
with open(DATA_FILE, "r") as file:
return json.load(file)
return {}
def save_data(data):
with open(DATA_FILE, "w") as file:
json.dump(data, file, indent=4)
def save_password(service, username, password):
data = load_data()
data[service] = {
"username": username,
"password": encrypt_password(password) }
save_data(data)
def get_password(service):
data = load_data()
if service in data:
entry = data[service]
entry["password"] = decrypt_password(entry["password"])
return entry
return None
def delete_password(service):
data = load_data()
if service in data:
del data[service]
save_data(data)
return True
return False
def list_services():
data = load_data()
if not data:
print("🚫 No services stored yet.")
return
print("🔍 Stored Sites/Services:")
for service in data:
print(f"- {service}")
def clear_all_passwords():
save_data({})
print("🆑 All saved services have been deleted.")