Last active
January 20, 2023 00:17
-
-
Save adamantonio/b719a60897a278b6b01d3ba8305a22c4 to your computer and use it in GitHub Desktop.
Password generator with GooeyPie - https://www.youtube.com/watch?v=TB0yo3fjaAM&ab_channel=CodingMechanism
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string | |
from random import choice | |
import gooeypie as gp | |
default_password_length = 8 | |
app = gp.GooeyPieApp('Password Generator') | |
app.resizable_vertical = False | |
def generate_password(length, letters, digits, symbols): | |
"""Returns a password with the given length and options""" | |
# Determine characters from which to choose from | |
available_chars = '' | |
if letters: | |
available_chars += string.ascii_letters | |
if digits: | |
available_chars += string.digits | |
if symbols: | |
available_chars += string.punctuation | |
# Make the password | |
new_password = '' | |
for count in range(length): | |
new_password += choice(available_chars) | |
return new_password | |
def show_new_password(event): | |
"""Populates the password box with a new generated password""" | |
# Check that at least one option is selected | |
if letters_chk.checked == False and digits_chk.checked == False and symbols_chk.checked == False: | |
app.alert('Invalid password options', 'Please select at least one option for the password', 'error') | |
else: | |
# Update length label | |
length_lbl.text = f'{length_sld.value} characters' | |
# Add password to password input | |
password_inp.text = generate_password(length_sld.value, letters_chk.checked, digits_chk.checked, symbols_chk.checked) | |
def copy_password(event): | |
app.copy_to_clipboard(password_inp.text) | |
# Create label containers | |
length_cont = gp.LabelContainer(app, 'Length') | |
options_cont = gp.LabelContainer(app, 'Options') | |
password_cont = gp.LabelContainer(app, 'Password') | |
# Length select | |
length_lbl = gp.Label(length_cont, f'{default_password_length} characters') | |
length_sld = gp.Slider(length_cont, 4, 50) | |
# Password options | |
letters_chk = gp.Checkbox(options_cont, 'Letters a-zA-Z') | |
digits_chk = gp.Checkbox(options_cont, 'Digits 0-9') | |
symbols_chk = gp.Checkbox(options_cont, 'Symbols ~!@#$%^&*()-_+[]{};:<>,.?') | |
letters_chk.checked = True | |
digits_chk.checked = True | |
symbols_chk.checked = True | |
# Generated password | |
password_inp = gp.Input(password_cont) | |
password_inp.width = 40 | |
reload_btn = gp.ImageButton(password_cont, 'reload.png', show_new_password) | |
copy_btn = gp.Button(password_cont, 'Copy to Clipboard', copy_password) | |
# Add all widgets to containers | |
length_cont.set_grid(2, 1) | |
length_cont.add(length_lbl, 1, 1) | |
length_cont.add(length_sld, 2, 1, fill=True) | |
options_cont.set_grid(3, 1) | |
options_cont.add(letters_chk, 1, 1) | |
options_cont.add(digits_chk, 2, 1) | |
options_cont.add(symbols_chk, 3, 1) | |
password_cont.set_grid(2, 2) | |
password_cont.set_column_weights(1, 0) | |
password_cont.add(password_inp, 1, 1, fill=True, stretch=True) | |
password_cont.add(reload_btn, 1, 2) | |
password_cont.add(copy_btn, 2, 1) | |
# Add all containers to main window | |
app.set_grid(3, 1) | |
app.add(length_cont, 1, 1, fill=True) | |
app.add(options_cont, 2, 1, fill=True) | |
app.add(password_cont, 3, 1, fill=True) | |
# Add event listeners to trigger password generation | |
letters_chk.add_event_listener('change', show_new_password) | |
digits_chk.add_event_listener('change', show_new_password) | |
symbols_chk.add_event_listener('change', show_new_password) | |
length_sld.add_event_listener('change', show_new_password) | |
# Set the slider to the default value, which will also trigger the generate function | |
length_sld.value = default_password_length | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have qooeypie installed on my computer, but VS code does not recognize it and underlines it with a yellow line as if the module is not installed, and I need help