diff --git a/code/password_strength/password_strength_gui.py b/code/password_strength/password_strength_gui.py index fd96da1..6a42d67 100644 --- a/code/password_strength/password_strength_gui.py +++ b/code/password_strength/password_strength_gui.py @@ -5,6 +5,7 @@ import tkinter as tk from tkinter.font import Font import customtkinter +from pynput.keyboard import Key, Controller from password_strength import password_strength_logic as logic import diacritics_fix as fix @@ -13,6 +14,8 @@ copy_button_y_offset = 30 +keyboard = Controller() + class PasswordStrengthFrame(customtkinter.CTkFrame): """ @@ -110,3 +113,15 @@ def display_warnings(entry_box: customtkinter.CTkEntry, w_labels: list, event: t w_labels[index].configure(text=warning) for label in w_labels: label.grid(column=0, row=2 + w_labels.index(label), sticky='w') + + +def paste_text() -> None: + """ + Called upon pressing the paste button, + this function uses the keyboard module to simulate pressing CTRL and V to paste text into the input_box. + """ + # https://youtu.be/DTnz8wA6wpw + keyboard.press(Key.ctrl_l) + keyboard.press('v') + keyboard.release(Key.ctrl_l) + keyboard.release('v') diff --git a/code/password_strength/password_strength_logic.py b/code/password_strength/password_strength_logic.py index d8d77b1..d379374 100644 --- a/code/password_strength/password_strength_logic.py +++ b/code/password_strength/password_strength_logic.py @@ -3,13 +3,10 @@ """ from __future__ import annotations import string -from pynput.keyboard import Key, Controller from collections.abc import Iterable from dataclasses import dataclass from pathlib import Path -keyboard = Controller() - # passwords.txt is from the https://github.com/danielmiessler/SecLists repository. # https://www.youtube.com/watch?v=DCaKj3eIrro passwords_file = Path('password_strength/passwords.txt') @@ -142,15 +139,3 @@ def check_for_patterns_in_password() -> str: pattern_warning = check_for_patterns_in_password() return [prevalence_warning, length_warning, complexity_warning, pattern_warning] - - -def paste_text() -> None: - """ - Called upon pressing the paste button, - this function uses the keyboard module to simulate pressing CTRL and V to paste text into the input_box. - """ - # https://youtu.be/DTnz8wA6wpw - keyboard.press(Key.ctrl_l) - keyboard.press('v') - keyboard.release(Key.ctrl_l) - keyboard.release('v')