-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path92. Simple Password Manager.py
More file actions
48 lines (42 loc) · 1.41 KB
/
92. Simple Password Manager.py
File metadata and controls
48 lines (42 loc) · 1.41 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
import json
def load_passwords():
try:
with open("passwords.json", "r") as file:
return json.load(file)
except FileNotFoundError:
return {}
def save_passwords(passwords):
with open("passwords.json", "w") as file:
json.dump(passwords, file)
def add_password(passwords, website, username, password):
passwords[website] = {"username": username, "password": password}
save_passwords(passwords)
print("Password added successfully!")
def view_passwords(passwords):
if passwords:
print("Stored Passwords:")
for website, data in passwords.items():
print(f"Website: {website}, Username: {data['username']}, Password: {data['password']}")
else:
print("No passwords stored.")
def main():
passwords = load_passwords()
while True:
print("\n1. Add Password")
print("2. View Passwords")
print("3. Exit")
choice = input("Enter your choice: ")
if choice == '1':
website = input("Enter website: ")
username = input("Enter username: ")
password = input("Enter password: ")
add_password(passwords, website, username, password)
elif choice == '2':
view_passwords(passwords)
elif choice == '3':
print("Exiting...")
break
else:
print("Invalid choice")
if __name__ == "__main__":
main()