forked from DeepNinja07x/Python_Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom_password_gui.py
120 lines (87 loc) · 2.98 KB
/
random_password_gui.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
'''Python program for generating random password'''
#Importing the modules
import tkinter as tk
from tkinter import ttk
import random
import string
#Data setting
lowercase = list(string.ascii_lowercase)
uppercase = list(string.ascii_uppercase)
digits = list(string.digits)
symbols = list(string.punctuation)
class Password:
"""Class for generating random strong passwords
Attributes:
length (int): Length of the password
pwd (str): The password
"""
def __init__(self, char, length):
self.char = char
self.length = length
self.charset = []
self.pwd = None
def setchar(self):
"""Setting character set."""
if 'l' in self.char: self.charset.extend(lowercase)
if 'u' in self.char: self.charset.extend(uppercase)
if 'd' in self.char: self.charset.extend(digits)
if 's' in self.char: self.charset.extend(symbols)
def password_gen(self):
"""Return the password
Returns:
str: The password
"""
if len(self.char) == 0:
self.charset.extend(lowercase)
if len(self.length) == 0:
self.length = 10 # By default, length is 10
else:
self.length = int(self.length)
pwdlist = random.choices(self.charset, k=self.length)
self.pwd = ''.join(pwdlist)
return self.pwd
wind = tk.Tk()
def generate():
global ch
if u.get(): ch += 'u'
if l.get(): ch += 'l'
if d.get(): ch += 'd'
if s.get(): ch += 's'
password = Password(ch, len_entry.get())
password.setchar()
pwd.set(password.password_gen())
ch = ''
# Initialise int variables
ch = ''
u = tk.IntVar()
d = tk.IntVar()
s = tk.IntVar()
l = tk.IntVar()
pwd = tk.StringVar()
# Main program
wind.title('Paasword Generator')
wind.geometry('400x300')
wind.resizable(0, 0)
head_label = ttk.Label(wind, text='Password Generator',
font=('Bodoni MT', 30, 'bold'))
head_label.grid(row=0, column=0, columnspan=2, pady=5)
len_label = ttk.Label(wind, text='Enter length', font=('Arial', 10))
len_label.grid(row=1, column=0, pady=10)
len_entry = ttk.Entry(wind, font=('Arial', 10, 'bold'))
len_entry.grid(row=1, column=1, pady=10)
upper_box = ttk.Checkbutton(wind, text='Uppercase', variable=u)
upper_box.grid(row=2, column=0)
lower_box = ttk.Checkbutton(wind, text='Lowercase', variable=l)
lower_box.grid(row=2, column=1)
digit_box = ttk.Checkbutton(wind, text='Digits', variable=d)
digit_box.grid(row=3, column=0)
symbol_box = ttk.Checkbutton(wind, text='Symbols', variable=s)
symbol_box.grid(row=3, column=1)
generate_button = ttk.Button(wind, text='Generate', command=generate)
generate_button.grid(row=4, column=0, columnspan=2, pady=10)
t_label = ttk.Label(wind, text=' Password :', font=('Arial', 10))
t_label.grid(row=5, column=0, pady=10)
password_disp = ttk.Entry(wind, font=('Arial', 10, 'bold'),
textvariable=pwd, width=30)
password_disp.grid(row=5, column=1, pady=10)
wind.mainloop()