-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordgenerator.py
More file actions
89 lines (67 loc) · 3.1 KB
/
Copy pathPasswordgenerator.py
File metadata and controls
89 lines (67 loc) · 3.1 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
import random
import tkinter as tk
import string
def generator(password_length: int, is_digit: bool = True, is_special: bool = True):
Letters = string.ascii_letters
Numbers = string.digits
Special = string.punctuation
character = Letters
if is_digit:
character += Numbers
if is_special:
character += Special
password = ""
password = "".join(random.SystemRandom().choice(character) for _ in range(password_length))
return password
def main():
window = tk.Tk()
window.title("Password generator")
icon = tk.PhotoImage(file="password.png")
window.iconphoto(True, icon)
heading = tk.Label(window, text="Password generator", font=("oswald", 50, "italic"),
fg="black", background="gold", relief="groove", pady=10)
heading.pack(pady=20)
length_label = tk.Label(window, text="Enter password length:", font=("oswald", 20), pady=10)
length_label.pack(pady=5)
length_entry = tk.Entry(window, font=("oswald", 20), relief="raised")
length_entry.pack(pady=2)
length_entry.bind('<Return>', lambda event: update_password())
numeric_label = tk.Label(window, text="Do you want numbers? (leave blank if not): ", font=("oswald", 20), pady=10)
numeric_label.pack(pady=5)
numeric_entry = tk.Entry(window, font=("oswald", 20), relief="raised")
numeric_entry.insert(0, 'True')
numeric_entry.pack(pady=2)
special_label = tk.Label(window, text="Do you want special characters? (leave blank if not): ",
font=("oswald", 20), pady=10)
special_label.pack(pady=5)
special_entry = tk.Entry(window, font=("oswald", 20))
special_entry.insert(0, 'True')
special_entry.pack(pady=2)
generated = tk.Label(window, text="Click the button to generate a password",
font=("oswald", 25, "italic"), relief="solid", pady=10)
generated.pack(pady=10)
def update_password():
password_length = length_entry.get()
if not password_length or int(password_length) <= 0:
generated.config(text="Error: Invalid password length")
return
password_length = int(password_length)
nums_check = bool(numeric_entry.get())
special_check = bool(special_entry.get())
password = generator(password_length, nums_check, special_check)
generated.config(text=password)
def copy_password():
if generated['text'] == "Click the button to generate a password":
return
window.clipboard_clear()
window.clipboard_append(generated['text'])
generated.config(text="Password copied!")
update_password_button = tk.Button(window, text="Generate password", font=("oswald", 20),
command=update_password, relief="raised", pady=20)
update_password_button.pack(pady=10)
copy_password_button = tk.Button(window, text="Copy password", font=("oswald", 20),
command=copy_password, relief="raised", pady=10)
copy_password_button.pack(pady=5)
window.mainloop()
if __name__ == '__main__':
main()