Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error handeling #90

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 30 additions & 24 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,36 @@ def main():
done = False
while not done:
choice = input("Enter choice: ").strip().lower()
if choice == '1':
path = input("Enter key file path: ").strip()
pm.create_key(path)
elif choice == '2':
path = input("Enter key file path: ").strip()
pm.load_key(path)
elif choice == '3':
path = input("Enter password file path: ").strip()
pm.create_password_file(path, password)
elif choice == '4':
path = input("Enter password file path: ").strip()
pm.load_password_file(path)
elif choice == '5':
site = input("Enter site: ").strip()
password = input("Enter password: ").strip()
pm.add_password(site, password)
elif choice == '6':
site = input("Enter site: ").strip()
print(f"Password for {site}: {pm.get_password(site)}")
elif choice == 'q':
done = True
print("Goodbye!")
else:
print("Invalid choice. Please try again.")
try:
if choice == '1':
path = input("Enter key file path: ").strip()
pm.create_key(path)
elif choice == '2':
path = input("Enter key file path: ").strip()
pm.load_key(path)
elif choice == '3':
path = input("Enter password file path: ").strip()
pm.create_password_file(path, password)
elif choice == '4':
path = input("Enter password file path: ").strip()
pm.load_password_file(path)
elif choice == '5':
site = input("Enter site: ").strip()
password = input("Enter password: ").strip()
pm.add_password(site, password)
elif choice == '6':
site = input("Enter site: ").strip()
print(f"Password for {site}: {pm.get_password(site)}")
elif choice == 'q':
done = True
print("Goodbye!")
else:
print("Invalid choice. Please try again.")
except Exception as e:
if str(e) == "KeyNotLoadedError":
print("Key not loaded. Please load a key first.")
else:
print(f"Something went wrong: {e} Please report this to the developer.")


if __name__ == '__main__':
Expand Down
2 changes: 2 additions & 0 deletions manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def load_password_file(self, path):
def add_password(self, site, password):
self.password_dict[site] = password
if self.password_file is not None:
if self.key is None:
raise Exception("KeyNotLoadedError")
with open(self.password_file, 'a+') as f:
encrypted = Fernet(self.key).encrypt(password.encode()).decode()
f.write(f"{site}:{encrypted}\n")
Expand Down