-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
190 lines (147 loc) 路 6.43 KB
/
Copy pathapp.py
File metadata and controls
190 lines (147 loc) 路 6.43 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
from tkinter import *
from tkinter import messagebox
from random import randint, choice, shuffle
import pyperclip
import json
"""
# Password Manager
A Password Manager with a GUI to store, manage, and retrieve passwords securely. It generates random passwords, copies them to the clipboard, and stores credentials in a JSON file with search and validation features.
## Screenshots
, 
## Author
Pranjal Sarnaik
## Features
- Generates strong random passwords.
- Automatically copies passwords to the clipboard.
- Validates input to ensure no fields are empty.
- Saves credentials in `data.json` and allows searching.
- Simple GUI with a lock icon for design appeal.
## Level
Intermediate
## Tech Stack
Python | Tkinter | JSON | File Handling | Clipboard Handling | Error Handling
## How to Run
1. Clone the repo:
```bash
git clone https://github.com/pranjalco/password-manager-intermediate.git
2. Run(Also install required libraries):
```bash
pip install pyperclip
python app.py
"""
FONT_NAME = "Courier"
# ---------------------------- PASSWORD GENERATOR ------------------------------- #
def generate_password():
password_entry.delete(0, END)
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 = ['!', '#', '$', '%', '&', '(', ')', '*', '+']
# Method 1 for creating random password list using for loop
password_list = [choice(letters) for _ in range(randint(8, 10))]
password_list += [choice(symbols) for _ in range(randint(2, 4))]
password_list += [choice(numbers) for _ in range(randint(2, 4))]
shuffle(password_list)
# Method 2 for creating random password list using for loop
# 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)
password = "".join(password_list)
password_entry.insert(0, f"{password}")
pyperclip.copy(password)
# ---------------------------- SAVE PASSWORD ------------------------------- #
def save():
website = website_entry.get()
password = password_entry.get()
email = email_username_entry.get()
new_data = {
website: {
"email": email,
"password": password, }
}
# Checking if fields are empty or not
if len(website) == 0 or len(password) == 0:
messagebox.showinfo(title="馃樋 mmm", message="Hi! Please enter all required details in fields.")
else:
# Asking user to cross-check the details
# is_ok = messagebox.askokcancel(title="Website", message=f"These are the details entered: "
# f"\nEmail: {email} \nPassword: {password} \nIs it ok to save?")
# Saving data to data.json file
is_ok = True
if is_ok:
try:
with open("data.json", "r") as data_file:
# Reading old data: reading
data = json.load(data_file)
# Updating old data with new data
data.update(new_data)
except FileNotFoundError:
with open("data.json", "w") as data_file:
json.dump(new_data, data_file, indent=4)
else:
with open("data.json", "w") as data_file:
# Saving the updated data: writing
json.dump(data, data_file, indent=4)
finally:
website_entry.focus()
website_entry.delete(0, "end")
password_entry.delete(0, "end")
# ----------------------- SEARCH INFORMATION -------------------------- #
def search_info():
website = website_entry.get()
if len(website) != 0:
try:
with open("data.json") as data_file:
data = json.load(data_file)
# print(data)
# print(type(data))
except FileNotFoundError:
messagebox.showerror(title="Error", message="No Data File Found")
else:
data_found = False
for key in data:
# This key will be website name
if key == website:
data_found = True
email = data[key]["email"]
password = data[key]["password"]
messagebox.showinfo(title=website, message=f"Email: {email} \nPassword: {password}")
if not data_found:
messagebox.showinfo(title=website, message=f"No data found for {website}.")
else:
messagebox.showinfo(title="Empty Website Field", message="Please enter something in Website field.")
# ---------------------------- UI SETUP ------------------------------- #
# Creating UI using tkinter module
window = Tk()
window.title("Password Manager")
window.config(padx=50, pady=50)
canvas = Canvas(width=200, height=200)
logo = PhotoImage(file="logo.png")
canvas.create_image(100, 100, image=logo)
canvas.grid(column=1, row=0)
website_label = Label(text="website:", font=(FONT_NAME))
website_label.grid(column=0, row=1)
website_entry = Entry(width=31)
website_entry.grid(column=1, row=1)
website_entry.focus()
email_username_label = Label(text="Email/Username:", font=(FONT_NAME))
email_username_label.grid(column=0, row=2)
email_username_entry = Entry(width=53)
email_username_entry.grid(column=1, row=2, columnspan=2)
email_username_entry.insert(0, "@gmail.com")
name = Label(text="Create by Pranjal Sarnaik")
name.grid(column=2, row=5)
password_label = Label(text="Password:", font=(FONT_NAME))
password_label.grid(column=0, row=3)
password_entry = Entry(width=31)
password_entry.grid(column=1, row=3)
generate_pass_button = Button(text="Generate Password", width=15, command=generate_password)
generate_pass_button.grid(column=2, row=3)
add_button = Button(text="Add", width=45, command=save)
add_button.grid(column=1, row=4, columnspan=2)
search_button = Button(text="Search", width=15, command=search_info)
search_button.grid(column=2, row=1)
window.mainloop()