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

Add warning delete #77

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
Binary file added __pycache__/manager.cpython-310.pyc
Binary file not shown.
8 changes: 8 additions & 0 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
10. Delete a password
q. Quit
""")

Expand All @@ -42,6 +43,13 @@ def main():
elif choice == '6':
site = input("Enter site: ").strip()
print(f"Password for {site}: {pm.get_password(site)}")
elif choice == '10':
site = input("Enter site to delete password: ").strip()
prompt = input(f"Confirm deleting password for {site} ? (y/n)").strip().lower()
if(prompt=="y"):
pm.delete_password(site)
else:
print("No changes made!")
elif choice == 'q':
done = True
print("Goodbye!")
Expand Down
14 changes: 14 additions & 0 deletions manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,17 @@ def add_password(self, site, password):

def get_password(self, site):
return self.password_dict.get(site, "Password not found.")
def delete_password(self, site):
if site in self.password_dict:
# Remove from the dictionary
del self.password_dict[site]
# Update the password file
if self.password_file is not None:
with open(self.password_file, 'r') as f:
lines = f.readlines()
with open(self.password_file, 'w') as f:
for line in lines:
if not line.startswith(site + ":"): # Skip the line with the site to delete
f.write(line)
else:
print("Site not found.")