Password Manager With Encryption
Password Manager With Encryption
import string
from cryptography.fernet import Fernet
passwords = {}
encryption_key = Fernet.generate_key()
cipher_suite = Fernet(encryption_key)
def generate_password(length):
chars = string.ascii_letters + string.digits + string.punctuation
password = ''
for _ in range(length):
password += random.choice(chars)
return password
def encrypt_data(data):
encrypted_data = cipher_suite.encrypt(data.encode())
return encrypted_data.decode()
def decrypt_data(encrypted_data):
decrypted_data = cipher_suite.decrypt(encrypted_data.encode())
return decrypted_data.decode()
def add_password():
website = input('Enter website: ')
username = input('Enter username: ')
suggest_password = input("Would you like a suggested password? (y/n) ")
if suggest_password.lower() == 'y':
password_length = int(input('Enter password length: '))
password = generate_password(password_length)
print('Suggested password:', password)
else:
password = input('Enter password: ')
encrypted_username = encrypt_data(username)
encrypted_password = encrypt_data(password)
passwords[website] = {'username': encrypted_username, 'password':
encrypted_password}
def get_password():
security = input("Say 'please' to get access to the passwords: ")
if security.lower() == "please":
website = input('Enter website: ')
if website in passwords:
encrypted_username = passwords[website]['username']
encrypted_password = passwords[website]['password']
decrypted_username = decrypt_data(encrypted_username)
decrypted_password = decrypt_data(encrypted_password)
print('Username:', decrypted_username)
print('Password:', decrypted_password)
else:
print('Website not found!')
else:
print("Access denied!")
def list_passwords():
with open('passwords.txt', 'r') as file:
for line in file:
website, encrypted_username, encrypted_password =
line.strip().split(',')
decrypted_username = decrypt_data(encrypted_username)
decrypted_password = decrypt_data(encrypted_password)
passwords[website] = {'username': decrypted_username, 'password':
decrypted_password}
print(website)
def delete_password():
website = input('Enter website to delete password: ')
if website in passwords:
del passwords[website]
with open('passwords.txt', 'r') as file:
lines = file.readlines()
with open('passwords.txt', 'w') as file:
for line in lines:
if not line.startswith(website):
file.write(line)
print('Password deleted successfully!')
else:
print('Website not found!')
while True:
print('1. Add password')
print('2. Get password')
print('3. List passwords')
print('4. Delete password')
print('5. Close')