|
| 1 | +import csv |
| 2 | +from cryptography.fernet import Fernet |
| 3 | + |
| 4 | +passwords = [] |
| 5 | +key = Fernet.generate_key() |
| 6 | +cipher_suite = Fernet(key) |
| 7 | + |
| 8 | +def encrypt_password(password): |
| 9 | + return cipher_suite.encrypt(password.encode()) |
| 10 | + |
| 11 | +def decrypt_password(encrypted_password): |
| 12 | + return cipher_suite.decrypt(encrypted_password).decode() |
| 13 | + |
| 14 | +def add_password(): |
| 15 | + website = input("Website: ") |
| 16 | + username = input("Username: ") |
| 17 | + password = input("Password: ") |
| 18 | + encrypted_password = encrypt_password(password) |
| 19 | + passwords.append({ |
| 20 | + "website": website, |
| 21 | + "username": username, |
| 22 | + "password": encrypted_password |
| 23 | + }) |
| 24 | + with open('passwords.csv', mode='a', newline='') as file: |
| 25 | + writer = csv.writer(file) |
| 26 | + writer.writerow([website, username, encrypted_password]) |
| 27 | + |
| 28 | +def get_password(website): |
| 29 | + for entry in passwords: |
| 30 | + if entry["website"] == website: |
| 31 | + username = entry["username"] |
| 32 | + encrypted_password = entry["password"] |
| 33 | + decrypted_password = decrypt_password(encrypted_password) |
| 34 | + print(f"Website: {website}") |
| 35 | + print(f"Username: {username}") |
| 36 | + print(f"Password: {decrypted_password}") |
| 37 | + return |
| 38 | + print("Website not found") |
| 39 | + |
| 40 | +with open('passwords.csv', mode='r') as file: |
| 41 | + reader = csv.reader(file) |
| 42 | + for row in reader: |
| 43 | + passwords.append({ |
| 44 | + "website": row[0], |
| 45 | + "username": row[1], |
| 46 | + "password": row[2] |
| 47 | + }) |
| 48 | + |
| 49 | +while True: |
| 50 | + print("\n1. Add Password") |
| 51 | + print("2. Get Password") |
| 52 | + print("3. Exit") |
| 53 | + |
| 54 | + choice = input("Enter your choice: ") |
| 55 | + |
| 56 | + if choice == '1': |
| 57 | + add_password() |
| 58 | + elif choice == '2': |
| 59 | + website = input("Enter website: ") |
| 60 | + get_password(website) |
| 61 | + elif choice == '3': |
| 62 | + break |
| 63 | + else: |
| 64 | + print("Invalid choice") |
0 commit comments