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

Password Usage Categories for better Organization | Closes Issue #37 #86

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
8 changes: 6 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def main():
4. Load an existing password file
5. Add a password
6. Get a password
7. List all passwords by category
q. Quit
""")

Expand All @@ -38,10 +39,13 @@ def main():
elif choice == '5':
site = input("Enter site: ").strip()
password = input("Enter password: ").strip()
pm.add_password(site, password)
category = input("Enter category (e.g., social, work, personal): ").strip()
pm.add_password(site, password,category)
elif choice == '6':
site = input("Enter site: ").strip()
print(f"Password for {site}: {pm.get_password(site)}")
print(pm.get_password(site))
elif choice == '7':
pm.list_passwords_by_category()
elif choice == 'q':
done = True
print("Goodbye!")
Expand Down
30 changes: 23 additions & 7 deletions manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,38 @@ def load_key(self, path):
def create_password_file(self, path, initial_values=None):
self.password_file = path
if initial_values is not None:
for site, password in initial_values.items():
self.add_password(site, password)
for site, data in initial_values.items():
self.add_password(site, data["password"], data.get("category"))

def load_password_file(self, path):
self.password_file = path
with open(path, 'r') as f:
for line in f:
site, encrypted = line.split(":")
self.password_dict[site] = Fernet(self.key).decrypt(encrypted.encode()).decode()
site, encrypted, category = line.strip().split(":")
password = Fernet(self.key).decrypt(encrypted.encode()).decode()
self.password_dict[site] = {"password": password, "category": category}

def add_password(self, site, password):
self.password_dict[site] = password
def add_password(self, site, password, category="uncategorized"):
self.password_dict[site] = {"password": password, "category": category}
if self.password_file is not None:
with open(self.password_file, 'a+') as f:
encrypted = Fernet(self.key).encrypt(password.encode()).decode()
f.write(f"{site}:{encrypted}\n")

def get_password(self, site):
return self.password_dict.get(site, "Password not found.")
data = self.password_dict.get(site)
if data:
return f"Password: {data['password']}, Category: {data['category']}"
return "Password not found."

def list_passwords_by_category(self):
selected_category = input("Enter the category you want to view: ").strip()
found = False
for site, data in self.password_dict.items():
if data["category"] == selected_category:
if not found:
print(f"\nCategory: {selected_category}")
found = True
print(f"{site}: {data['password']}")
if not found:
print(f"No passwords found for category: {selected_category}")