-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPassword Generator.py
More file actions
41 lines (35 loc) · 1.42 KB
/
Copy pathPassword Generator.py
File metadata and controls
41 lines (35 loc) · 1.42 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
import random
import string
import PySimpleGUI as sg
sg.theme('Dark Amber 5')
sg.set_options(font='verdana 15')
layout = [
[sg.Text('Uppercase: '), sg.Input(size=(15, 1), key='-UP-')],
[sg.Text('Lowercase: '), sg.Input(size=(15, 1), key='-LOW-')],
[sg.Text('Digits: '), sg.Input(size=(15, 1), key='-DIG-')],
[sg.Text('Symbols: '), sg.Input(size=(15, 1), key='-SYM-')],
[sg.Button('Ok'), sg.Button('Cancel')],
[sg.Text('Password'), sg.Multiline(size=(15, 3), no_scrollbar=True, disabled=True, key='-PASS-')],
]
window = sg.Window('Password Generator', layout)
while True:
event, values = window.read()
if event == sg.WINDOW_CLOSED or event == 'Cancel':
break
if event == 'Ok':
try:
u_upper = int(values['-UP-'])
upper = random.sample(string.ascii_uppercase, u_upper)
u_lower = int(values['-LOW-'])
lower = random.sample(string.ascii_lowercase, u_lower)
u_digits = int(values['-DIG-'])
digits = random.sample(string.digits, u_digits)
u_symbols = int(values['-SYM-'])
symbols = random.sample(string.punctuation, u_symbols)
total = upper + lower + digits + symbols
total = random.sample(total, len(total))
total = ''.join(total)
window['-PASS-'].update(total)
except ValueError:
window['-PASS-'].update("No valid number")
window.close()