-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodsoft_taskno.3.py
62 lines (45 loc) · 1.85 KB
/
codsoft_taskno.3.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
import tkinter as tk
import random
import string
def generate_password(length, complexity):
if complexity == "medium":
characters = string.ascii_letters + string.digits
elif complexity == "strong":
characters = string.ascii_letters + string.digits + string.punctuation
elif complexity == "very strong":
characters = string.ascii_letters + string.digits + string.punctuation + string.ascii_uppercase + string.digits + string.punctuation
if not characters:
return "Error: Invalid complexity level."
password = ''.join(random.choice(characters) for _ in range(length))
return password
def generate_and_display_password():
length = int(entry_length.get())
complexity = complexity_var.get()
password = generate_password(length, complexity)
password_text.delete("1.0", tk.END) # Clear previous text
password_text.insert(tk.END, password)
root = tk.Tk()
root.title("Password Generator")
length_label = tk.Label(root, text="Enter the desired length of the password:")
entry_length = tk.Entry(root)
complexity_label = tk.Label(root, text="Select the complexity level:")
complexity_var = tk.StringVar()
complexity_var.set("medium")
complexity_radios = [
("Medium", "medium"),
("Strong", "strong"),
("Very Strong", "very strong")
]
for text, value in complexity_radios:
radio = tk.Radiobutton(root, text=text, variable=complexity_var, value=value)
radio.pack(anchor=tk.W)
generate_button = tk.Button(root, text="Generate Password", command=generate_and_display_password)
password_label = tk.Label(root, text="Generated Password:")
password_text = tk.Text(root, height=1, width=30)
length_label.pack()
entry_length.pack()
complexity_label.pack()
generate_button.pack()
password_label.pack()
password_text.pack()
root.mainloop()