Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
153 lines (138 loc) · 4.51 KB
/
Copy pathmain.py
File metadata and controls
153 lines (138 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import os
import pandas
import pyperclip
import json
from tkinter import *
from tkinter import messagebox
from password import Password
FONT_NAME = "Rockwell"
#Password Generator
password_manager: Password = Password()
def generate():
global password_manager
password = password_manager.create()
if not password_entry:
password = password_manager.create()
password_entry.insert(0, password)
else:
password_entry.delete(0, END)
password_entry.insert(0, password)
pyperclip.copy(password)
def find_password():
website = website_entry.get()
try:
with open("data.json", "r") as data_file:
data = json.load(data_file)
except FileNotFoundError:
messagebox.showinfo(title="Oops", message="No data file found")
else:
if website in data:
messagebox.showinfo(title=website, message=f"Email: {data[website]['email']}\n"
f"Password: {data[website]['password']}")
pyperclip.copy(data[website]['password'])
else:
messagebox.showinfo(title='Oops', message=f'No details found for this website: {website}')
#Save Password
def save():
website = website_entry.get()
password = password_entry.get()
user = email_entry.get()
new_data = {
website: {
"email": user,
"password": password
}
}
if not website or not password or not user:
messagebox.showinfo(title="Oops", message="Please leave no fields empty!")
else:
is_ok = messagebox.askokcancel(title=website, message=f"These are the details entered: \nEmail/Username: {user}\nPassword: {password}\nIs it okay to save?")
if is_ok:
data = {
"Website": [website],
"Email/Username": [user],
"Password": [password]
}
data_csv = pandas.DataFrame(data)
if os.path.exists("data.csv"):
data_csv.to_csv("data.csv", mode="a", header=False, index=False)
else:
data_csv.to_csv("data.csv", index=False)
# WRITING TO JSON FILES
try:
with open("data.json", "r") as data_file:
data = json.load(data_file)
except FileNotFoundError:
with open("data.json", "w") as data_file:
json.dump(new_data, data_file, indent=4)
else:
data.update(new_data)
with open("data.json", "w") as data_file:
json.dump(data, data_file, indent=4)
finally:
website_entry.delete(0, END)
password_entry.delete(0, END)
# UI Setup
window = Tk()
window.title("Password Manager")
window.config(padx=40, pady=40)
canvas = Canvas(width=200, height=210, highlightthickness=0)
logo_img = PhotoImage(file="logo1.png")
canvas.create_image(100, 100, image=logo_img)
logo_text = canvas.create_text(100, 185, text="MyPass", fill="#037ce4", font=(FONT_NAME, 20, "bold"))
canvas.grid(column=1, row=0)
website_label = Label(text="Website:", font=("Georgia", 10, "normal"))
website_label.grid(column=0, row=1)
website_entry = Entry(width=32)
website_entry.grid(row=1, column=1)
website_entry.focus()
email_label = Label(text="Email/Username:", font=("Georgia", 10, "normal"))
email_label.grid(column=0, row=2)
email_entry = Entry(width=50)
email_entry.grid(row=2, column=1, columnspan=2)
email_entry.insert(0, "chukwug996@gmail.com")
password_label = Label(text="Password:", font=("Georgia", 10, "normal"))
password_label.grid(column=0, row=3)
password_entry = Entry(width=32)
password_entry.grid(row=3, column=1, padx=0)
generate_btn = Button(
text="Generate Password",
width=15,
relief="flat",
highlightthickness=0,
bd=0,
command = generate,
bg="#037ce4",
fg="white",
activeforeground="white",
activebackground="#2f4bc0"
)
generate_btn.grid(row=3, column=2, padx=0, pady=(3, 0))
search_btn = Button(
text="Search",
width=15,
relief="flat",
highlightthickness=0,
bd=0,
command= find_password,
bg= "#037ce4",
fg= "white",
activeforeground= "white",
activebackground= "#2f4bc0"
)
search_btn.grid(row=1, column=2, padx=0, pady=(0, 0))
add_btn = Button(
text="Add",
width=43,
relief="solid",
bd=0,
fg="white",
bg="#037ce4",
command=save,
activeforeground="white",
highlightthickness=0,
highlightbackground="#2f4bc0",
activebackground="#2f4bc0"
)
add_btn.grid(row=4, column=1, columnspan=2, pady=5)
window.mainloop()