0% found this document useful (0 votes)
21 views

Password Manager With Encryption

This Python program manages passwords securely by encrypting them before storing. It allows the user to add, get, list, and delete passwords by interacting with a menu. Passwords are encrypted using the Fernet encryption method and stored in a text file along with the website. The program decrypts passwords when retrieving and lists them.

Uploaded by

Omkar Honalikar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Password Manager With Encryption

This Python program manages passwords securely by encrypting them before storing. It allows the user to add, get, list, and delete passwords by interacting with a menu. Passwords are encrypted using the Fernet encryption method and stored in a text file along with the website. The program decrypts passwords when retrieving and lists them.

Uploaded by

Omkar Honalikar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import random

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}

with open('passwords.txt', 'a') as file:


file.write(f"{website},{encrypted_username},{encrypted_password}\n")

print('Password added successfully!')

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')

choice = input('Enter your choice: ')


if choice == '1':
add_password()
elif choice == '2':
get_password()
elif choice == '3':
list_passwords()
elif choice == '4':
delete_password()
elif choice == '5':
break
else:
print('Invalid choice!')

You might also like