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

Update main.py #797

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
114 changes: 64 additions & 50 deletions projects/Password Projects/Password_manager/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,28 @@ def searc():
try:
with open("data.json", "r") as f:
d = json.load(f)
p = d[webinput.get()]["password"]
e = d[webinput.get()]["email"]
messagebox.showinfo(
title=f"{webinput.get()}", message=f"Email is {e} \n password is {p}"
)

except KeyError:
messagebox.showinfo(title="Not Found", message="Data not found")
website = webinput.get()
if website in d:
email = d[website]["email"]
password = d[website]["password"]

# Update the entry fields directly
emailinput.delete(0, END)
emailinput.insert(0, email)
passinput.delete(0, END)
passinput.insert(0, password)
else:
messagebox.showinfo(title="Not Found", message="Data not found for the website.")
except FileNotFoundError:
messagebox.showinfo(title="Warning", message="File missing")
messagebox.showinfo(title="Warning", message="Data file not found. Please save a password first.")
except json.JSONDecodeError:
messagebox.showinfo(title="Error", message="Error reading data file. Please check the file format.")



# ---------------------------- PASSWORD GENERATOR ------------------------------- #
def generator():
passinput.delete(0, END) # Clear previous password
passinput.insert(0, generatedpass())


Expand All @@ -31,67 +39,73 @@ def savedata():
email = emailinput.get()
passwo = passinput.get()
new_data = {website: {"email": email, "password": passwo}}
if emailinput.get() == "" or webinput.get() == "" or passinput.get() == "":
messagebox.showinfo(
title="Warning", message="Please fill all the enteries to proceed"
)
else:
is_ok = messagebox.askokcancel(
title=webinput.get(),
message=f"Check all details \n Password : {passinput.get()} \n email : {emailinput.get()} ",
)
if is_ok:
try:
with open("data.json", "r") as f:
data = json.load(f)
data[website] = new_data[website]
with open("data.json", "w") as f:
json.dump(data, f, indent=4)
except:
with open("data.json", "w") as f:
json.dump(new_data, f, indent=4)

emailinput.delete(0, END)
webinput.delete(0, END)
passinput.delete(0, END)

if not website or not email or not passwo:
messagebox.showinfo(title="Warning", message="Please fill in all fields to proceed.")
return

is_ok = messagebox.askokcancel(
title=website,
message=f"Check all details\nPassword: {passwo}\nEmail: {email}"
)

if is_ok:
try:
with open("data.json", "r") as f:
data = json.load(f)
except (FileNotFoundError, json.JSONDecodeError):
data = {}

data.update(new_data)

with open("data.json", "w") as f:
json.dump(data, f, indent=4)

webinput.delete(0, END)
emailinput.delete(0, END)
passinput.delete(0, END)


# ---------------------------- UI SETUP ------------------------------- #

window = Tk()

window.title("Password Managger")
window.title("Password Manager")
window.config(padx=50, pady=50)
canva = Canvas(width=200, height=200)
log = PhotoImage(file="logo.png")
canva.create_image(100, 100, image=log)
canva.grid(row=0, column=1)

website = Label(text="Website")
website.grid(row=1, column=0)
canvas = Canvas(width=200, height=200)
logo = PhotoImage(file="logo.png")
canvas.create_image(100, 100, image=logo)
canvas.grid(row=0, column=1)

# Labels
website_label = Label(text="Website:")
website_label.grid(row=1, column=0)

email = Label(text="Email")
email.grid(row=2, column=0)
email_label = Label(text="Email:")
email_label.grid(row=2, column=0)

Password = Label(text="Password")
Password.grid(row=3, column=0)
password_label = Label(text="Password:")
password_label.grid(row=3, column=0)

# Entries
webinput = Entry(width=30)
webinput.grid(row=1, column=1)
webinput.focus() # Focus on website input on start

emailinput = Entry(width=30)
emailinput.grid(row=2, column=1)

passinput = Entry(width=30)
passinput.grid(row=3, column=1)

genbtn = Button(text="genetrate", command=generator)
genbtn.grid(row=3, column=2)
# Buttons
generate_button = Button(text="Generate", command=generator)
generate_button.grid(row=3, column=2)

add = Button(text="ADD", width=36, command=savedata)
add.grid(row=4, column=1, columnspan=2)
add_button = Button(text="Add", width=36, command=savedata)
add_button.grid(row=4, column=1, columnspan=2)

search = Button(text="Search", command=searc)
search.grid(row=1, column=2)
search_button = Button(text="Search", command=searc)
search_button.grid(row=1, column=2)

window.mainloop()
Loading