-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
122 lines (91 loc) · 4.11 KB
/
main.py
File metadata and controls
122 lines (91 loc) · 4.11 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
from tkinter import *
from tkinter import messagebox
from random import randint, choice, shuffle
import json
# import pyperclip
# ---------------------------- PASSWORD GENERATOR ------------------------------- #
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
symbols = ['!', '#', '$', '%', '&', '(', ')', '*', '+']
def find_password():
try:
with open("data.json", mode="r") as entry:
websites = json.load(entry)
except FileNotFoundError:
messagebox.showerror(title="Error", message="No Data File Found.")
except json.decoder.JSONDecodeError:
messagebox.showinfo(title="Empty File", message="The File Is Empty")
else:
if web_url.get() in websites:
mail = websites[web_url.get()]["email"]
web_password = websites[web_url.get()]["password"]
messagebox.showinfo(title=f"{web_url.get()}", message=f"Email: {mail}\nPassword: {web_password}")
elif len(web_url.get()) == 0:
messagebox.showinfo(title="Error", message=f"Input the name of the website you want to search.")
else:
messagebox.showinfo(title="Error", message=f"Not details for {web_url.get()} exists.")
def generate_password():
password_letters = [choice(letters) for _ in range(randint(8, 10))]
password_symbols = [choice(symbols) for _ in range(randint(2, 4))]
password_numbers = [choice(numbers) for _ in range(randint(2, 4))]
password_list = password_letters + password_symbols + password_numbers
shuffle(password_list)
pass_word = "".join(password_list)
password_input.insert(0, pass_word)
# pyperclip.copy(pass_word)
# ---------------------------- SAVE PASSWORD ------------------------------- #
def save():
new_data = {
web_url.get(): {
"email": username_input.get(),
"password": password_input.get()
}
}
if len(web_url.get()) == 0 or len(username_input.get()) == 0 or len(password_input.get()) == 0:
messagebox.showinfo(title="Oops", message="Please don't leave any fields empty!")
else:
try:
with open("data.json", mode="r") as data:
content = json.load(data)
except FileNotFoundError:
with open("data.json", mode="w") as data:
json.dump(new_data, data, indent=4)
else:
content.update(new_data)
with open("data.json", mode="w") as data:
json.dump(content, data, indent=4)
finally:
web_url.delete(0, END)
password_input.delete(0, END)
# ---------------------------- UI SETUP ------------------------------- #
window = Tk()
window.title("Password Manager")
window.config(padx=50, pady=50)
canvas = Canvas(width=200, height=200, highlightthickness=0)
padlock_img = PhotoImage(file="logo.png")
canvas.create_image(100, 100, image=padlock_img)
canvas.grid(row=0, column=1)
website = Label(text="Website:")
website.grid(row=1, column=0)
username = Label(text="Email/Username:")
username.grid(row=2, column=0)
password = Label(text="Password:")
password.grid(row=3, column=0)
web_url = Entry(width=32)
web_url.grid(row=1, column=1)
web_url.focus()
username_input = Entry(width=51)
username_input.grid(row=2, column=1, columnspan=2)
username_input.insert(0, "john@gmail.com")
password_input = Entry(width=32)
password_input.grid(row=3, column=1)
search_button = Button(text="Search", command=find_password, width=14)
search_button.grid(row=1, column=2)
generate_pass_button = Button(text="Generate Password", command=generate_password)
generate_pass_button.grid(row=3, column=2)
add_button = Button(text="Add", width=43, command=save)
add_button.grid(row=4, column=1, columnspan=2)
window.mainloop()