-
Notifications
You must be signed in to change notification settings - Fork 0
/
password.py
55 lines (44 loc) · 1.78 KB
/
password.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
import random
import string
from tkinter import *
from tkinter import ttk
root = Tk()
strength = IntVar()
length = DoubleVar()
root.title('Password Generator')
def pass_gen(event):
lengthy = int(PassLength.get())
if strength.get() == 1:
list = []
for i in range(0, lengthy):
list.append(random.choice(string.ascii_letters))
password = ''.join(list)
PassField.delete(0, 'end')
PassField.insert(0, password)
elif strength.get() == 2:
list = []
for i in range(0, lengthy):
list.append(random.choice(string.digits + string.ascii_letters))
password = ''.join(list)
PassField.delete(0, 'end')
PassField.insert(0, password)
elif strength.get() == 3:
list = []
for i in range(0, lengthy):
list.append(random.choice(string.punctuation + string.digits + string.ascii_letters))
password = ''.join(list)
PassField.delete(0, 'end')
PassField.insert(0, password)
Radiobutton(root, text="Weak", variable=strength, value=1).grid(row=0, column=0, sticky=N)
Radiobutton(root, text="Strong", variable=strength, value=2).grid(row=0, column=1, sticky=N)
Radiobutton(root, text="Extra-strong", variable=strength, value=3).grid(row=0, column=2, sticky=N)
Label(root, text='Length').grid(row=1, column=0, sticky=W, padx=4)
PassLength = Scale(root, variable=length, from_=0, to=20, orient=HORIZONTAL)
PassLength.grid(row=1, column=1)
Label(root, text='Password').grid(row=2, sticky=W, padx=4)
PassField = Entry(root)
PassField.grid(row=2, column=1, sticky=E, pady=4)
generateButton = Button(root, text='Generate')
generateButton.bind("<Button-1>", pass_gen)
generateButton.grid(row=2, column=2,sticky=E)
root.mainloop()