This code represents a Student Password Generator application that allows users to generate random passwords for students listed in a PDF file. The application is built using Python with a customtkinter GUI framework for the user interface and PyMuPDF (fitz) and FPDF libraries for handling PDF files. Below is a detailed description of the code:
- Key Components logic.py Purpose: Contains the core logic for extracting student names from a PDF, generating random passwords, and saving the passwords to a new PDF.
Functionality:
Extract Student Names:
Uses fitz (PyMuPDF) to read a PDF file and extract student names from the text.
Returns a list of student names after cleaning and filtering.
Generate Passwords:
Generates random passwords of a specified length using a combination of letters, digits, and punctuation.
Save Passwords to PDF:
Uses FPDF to create a new PDF file containing a table of student names and their corresponding passwords.
Key Features:
Random password generation with customizable length.
PDF handling for both input (student list) and output (password list).
ui.py Purpose: Provides a graphical user interface (GUI) for the password generator application.
Functionality:
PDF File Selection:
Allows users to browse and select a PDF file containing student names.
Password Length Input:
Lets users specify the length of the generated passwords (default is 8 characters).
Generate Passwords:
Calls the logic.py functions to extract student names and generate passwords.
Displays the generated passwords in a text box.
Save to PDF:
Saves the generated passwords to a new PDF file using the save_passwords_to_pdf function from logic.py.
Key Features:
Built using customtkinter for a modern and customizable UI.
Error handling for invalid inputs (e.g., missing PDF file, non-numeric password length).
Success and error messages using messagebox.
- Workflow User Interaction:
The user selects a PDF file containing student names using the "Browse" button.
The user specifies the desired password length (default is 8 characters).
Password Generation:
The application extracts student names from the PDF using extract_students_from_pdf.
Random passwords are generated for each student using create_passwords.
The generated passwords are displayed in the text box.
Save Passwords:
The user can save the generated passwords to a new PDF file using the "Save to PDF" button.
The passwords are saved in a table format with columns for student names and passwords.
- Key Features PDF Handling:
The application can read student names from a PDF file and save the generated passwords to a new PDF.
Uses fitz (PyMuPDF) for reading PDFs and FPDF for creating PDFs.
Random Password Generation:
Passwords are generated using a combination of letters, digits, and punctuation.
The password length is customizable by the user.
User Interface:
Built with customtkinter, providing a modern and responsive UI.
Includes features like file browsing, input validation, and success/error messages.
Error Handling:
The application handles errors such as missing PDF files, invalid password lengths, and issues during PDF creation.
- Improvements and Considerations Improvements: Enhanced PDF Parsing:
Improve the logic for extracting student names to handle more complex PDF formats (e.g., tables, multi-column layouts).
Password Complexity Options:
Allow users to customize the complexity of passwords (e.g., include/exclude special characters, numbers).
Export Options:
Add support for exporting passwords to other formats (e.g., CSV, Excel).
Batch Processing:
Allow users to process multiple PDF files at once.
Considerations: Security: Ensure that the generated passwords are securely stored and transmitted if the application is extended to a networked environment.
Scalability: The current implementation is suitable for small to medium-sized student lists. For larger datasets, consider optimizing the PDF handling and password generation logic.
- Summary This Student Password Generator application is a simple yet effective tool for generating random passwords for students listed in a PDF file. It combines PDF handling, random password generation, and a modern GUI to provide a user-friendly experience. The application is ideal for educational institutions or organizations that need to generate and distribute passwords for students or users. With some enhancements, it can be adapted for more complex use cases.