-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassword_to_txt_file.py
100 lines (73 loc) · 3.58 KB
/
password_to_txt_file.py
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
# save passwords in text file (data.txt)
from tkinter import *
from tkinter import messagebox
import random
import pyperclip # use to copy something
FONT = ("times new roman", 14)
# ----------------------- PASSWORD GENERATOR ------------------------
def generate_password():
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 = ['!', '#', '$', '%', '&', '(', ')', '*', '+']
nr_letters = random.randint(5, 10)
nr_symbols = random.randint(2, 4)
nr_numbers = random.randint(2, 4)
password_list = []
[password_list.append(random.choice(letters)) for _ in range(nr_letters)]
[password_list.append(random.choice(symbols)) for _ in range(nr_symbols)]
[password_list.append(random.choice(numbers)) for _ in range(nr_numbers)]
# print(f"{''.join(password_list)}")
random.shuffle(password_list)
password = ""
for char in password_list:
password += char
password_entry.insert(END, password)
pyperclip.copy(password)
# print(f"Your password is: {password}")
# ----------------------- SAVE PASSWORD -------------------------
def save_password():
website = website_entry.get()
email = email_entry.get()
password = password_entry.get()
if not website or not password or not email: # if any field empty
messagebox.showerror(title="OOPS", message="Please don't leave any field empty.")
else:
is_ok = messagebox.askokcancel(title=website, message=f"These are the details entered:\n\nEmail: {email}"
f"\nPassword: {password}\n\nIs is ok to save?")
if is_ok:
with open("data.txt", "a") as data:
data.write(f"website: {website} | email: {email} | password: {password}\n")
website_entry.delete(0, END)
password_entry.delete(0, END)
# ----------------------- UI SETUP ------------------------
window = Tk()
window.title("Password Manager")
window.config(pady=50, padx=50)
canvas = Canvas(width=200, height=200, bg='sky blue', highlightthickness=0)
logo_img = PhotoImage(file="logo.png")
canvas.create_image((100, 100), image=logo_img)
canvas.grid(row=0, column=1, pady=20)
# ------- label ----------
website_label = Label(pady=5, text="website:", font=FONT)
website_label.grid(row=1, column=0) # sticky="e"
email_label = Label(pady=5, text="email id/username:", font=FONT)
email_label.grid(row=2, column=0)
password_label = Label(pady=5, text="password:", font=FONT)
password_label.grid(row=3, column=0) # sticky="e"
# --------- entry ----------
website_entry = Entry(width=50, font=FONT)
website_entry.focus()
website_entry.grid(row=1, column=1, columnspan=2, )
email_entry = Entry(width=50, font=FONT)
email_entry.insert(END, "[email protected]") # set a default mail
email_entry.grid(row=2, column=1, columnspan=2)
password_entry = Entry(width=34, font=FONT)
password_entry.grid(row=3, column=1, sticky="w")
# ---------- buttons -----------
password_generate_button = Button(text="generate password", bg="#a1ccd1", font=("times new roman", 13,), command=generate_password)
password_generate_button.grid(row=3, column=2)
add_button = Button(text="add", width=50, bg="#a1ccd1", font=("times new roman", 13,), command=save_password)
add_button.grid(row=4, column=1, columnspan=2)
window.mainloop()