Artificial Intelligence
Please fill the required field.

import os import shutil import subprocess import tkinter as tk from tkinter import filedialog, messagebox def find_gpp(): candidates = [ shutil.which("g++"), r"C:\msys64\mingw64\bin\g++.exe" ] for path in candidat


Certainly! To implement a password-checking mechanism in your existing script, we will prompt the user for a password before proceeding with the file selection and compilation. If the entered password matches "mynameisgavinandimadumbass", the program will continue; otherwise, it will display an error message and exit. Below is the modified code with the password check included: ```python import os import shutil import subprocess import tkinter as tk from tkinter import filedialog, messagebox def find_gpp(): candidates = [ shutil.which("g++"), r"C:\msys64\mingw64\bin\g++.exe" ] for path in candidates: if path and os.path.exists(path): return path return None def compile_cpp_file(file_path): gpp = find_gpp() if not gpp: messagebox.showerror( "Compiler not found", "g++ was not found.\n\n" "Make sure MSYS2 MinGW64 is installed:\n" "pacman -S mingw-w64-x86_64-gcc" ) return output_exe = os.path.splitext(file_path)[0] + ".exe" result = subprocess.run( [gpp, file_path, "-std=c++17", "-O2", "-Wall", "-o", output_exe], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True ) if result.returncode == 0: messagebox.showinfo("Success", f"Compiled successfully:\n{output_exe}") else: messagebox.showerror( "Compilation failed", result.stderr or "Unknown compilation error" ) def check_password(): password = "mynameisgavinandimadumbass" def verify_password(): entered_password = entry.get() if entered_password == password: dialog.destroy() main() else: messagebox.showerror("Access Denied", "Incorrect Password") dialog.destroy() dialog = tk.Toplevel() dialog.title("Password Required") tk.Label(dialog, text="Enter Password:").pack(pady=10) entry = tk.Entry(dialog, show='*') entry.pack(pady=10) tk.Button(dialog, text="Submit", command=verify_password).pack(pady=10) dialog.mainloop() def main(): root = tk.Tk() root.withdraw() file_path = filedialog.askopenfilename( title="Select a C++ file", filetypes=[("C++ files", "*.cpp")] ) if file_path: compile_cpp_file(file_path) if __name__ == "__main__": check_password() ``` ### Key Modifications: 1. **Password Check Function**: A new function `check_password` is added to manage password input. 2. **Password Input Dialog**: The user is prompted to enter a password. If the password is correct, it calls the `main` function. Otherwise, it shows an error message. 3. **Security**: The password is displayed as asterisks for security. 4. **Main Program Flow**: The call to `main()` is now inside the `check_password()` function after successful password verification. Make sure to run the code in an appropriate environment that supports Tkinter for the user interface.