Added Password Manager

This commit is contained in:
Khushi Jha 2022-10-15 20:42:36 +05:30 committed by GitHub
parent 3a1ddfad4a
commit e8fe10fdc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,50 @@
from cryptography.fernet import Fernet
'''
def write_key():
key = Fernet.generate_key()
with open("key.key", "wb") as key_file:
key_file.write(key)'''
def load_key():
file = open("key.key", "rb")
key = file.read()
file.close()
return key
key = load_key()
fer = Fernet(key)
def view():
with open('passwords.txt', 'r') as f:
for line in f.readlines():
data = line.rstrip()
user, passw = data.split("|")
print("User:", user, "| Password:",
fer.decrypt(passw.encode()).decode())
def add():
name = input('Account Name: ')
pwd = input("Password: ")
with open('passwords.txt', 'a') as f:
f.write(name + "|" + fer.encrypt(pwd.encode()).decode() + "\n")
while True:
mode = input(
"Would you like to add a new password or view existing ones (view, add), press q to quit? ").lower()
if mode == "q":
break
if mode == "view":
view()
elif mode == "add":
add()
else:
print("Invalid mode.")
continue

View File

@ -0,0 +1,2 @@
joe|gAAAAABgjFWyJO-TuQzczus2VTKZEkiQm40dWlU49uG4s0KztOLsTMCXUDN7DSSytU7w9ArgVZzhvt3oivFfFty1DwO0yZ71Fw==
billy|gAAAAABgjFYUZ22T15aXZyx72CpbC0Rd6hRcxq82RiAMn5Pj2WoMyzy8zAInqvwhg04LNWsW7lnlx3_RHpEEQ9fzhIYG9F0-lA==