Skip to content

Commit

Permalink
Update Windows-Account-Creator.py
Browse files Browse the repository at this point in the history
+ Add better exception handling
+ Password must now be atleast 5 Characters with Special Characters and be a little complex
+ Message success and error while runtime
  • Loading branch information
H14d3n committed Aug 14, 2024
1 parent 9952580 commit 236fde7
Showing 1 changed file with 65 additions and 39 deletions.
104 changes: 65 additions & 39 deletions src/CustomTKinter/Windows-Account-Creator.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,63 @@
from tkinter import *
import customtkinter
import subprocess
import os
import ctypes
import subprocess
import customtkinter
from tkinter import BooleanVar

# Theme of Application
customtkinter.set_appearance_mode("dark")
customtkinter.set_default_color_theme("blue")
customtkinter.deactivate_automatic_dpi_awareness()

special_characters = ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '=', '+', '{', '}', '[', ']', '|', '\\', ':', ';', '"', "'", '<', '>', ',', '.', '?', '/', '~', '`']
alphabet_characters = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

# Function to create account
def create_account():
# Get Username and save into new var
# Get Username and Password
end_username = username.get()
end_password = password.get()
is_checked = admin_check_var.get()

# Take variables and execute command
user_command = f"net user {end_username} {end_password} /add"
if len(end_username) > 0 and len(end_password) >= 5:

print("Executing command:", user_command)

try:
subprocess.run(user_command, shell=True, check=True)
print("User created successfully!")
except subprocess.CalledProcessError as e:
print("Error creating user:", e)
return

# If checkbox is checked, add user to administrator group
if is_checked:
admin_group_name = determine_admin_group()

if admin_group_name:
admin_command = f"net localgroup \"{admin_group_name}\" {end_username} /add"
print("Executing command:", admin_command)

try:
subprocess.run(admin_command, shell=True, check=True)
print(f"User '{end_username}' added to {admin_group_name} group successfully.")
except subprocess.CalledProcessError as e:
print(f"Error adding user to {admin_group_name} group: {e}")
return
if any(char in end_password for char in special_characters):
if "12345" in end_password:
error_message("More Complex Password")
elif not any(char in end_password for char in alphabet_characters):
error_message("Password must contain letters")
elif not run_as_admin():
error_message("Run program as administrator")
else:
# Create user account
user_command = f"net user {end_username} {end_password} /add"
print("Executing command:", user_command)
try:
subprocess.run(user_command, shell=True, check=True)
success_message("User created successfully!")
except subprocess.CalledProcessError as e:
error_message(f"Error creating user: {e}")
return

# Add user to administrator group if checkbox is checked
if is_checked:
admin_group_name = determine_admin_group()
if admin_group_name:
admin_command = f"net localgroup \"{admin_group_name}\" {end_username} /add"
print("Executing command:", admin_command)
try:
subprocess.run(admin_command, shell=True, check=True)
success_message(f"User '{end_username}' added to {admin_group_name} group successfully.")
except subprocess.CalledProcessError as e:
error_message(f"Error adding user to {admin_group_name} group: {e}")
else:
error_message("No suitable admin group found.")
else:
print("No suitable admin group found.")
error_message("Password should contain special characters")
else:
error_message("Username or password too short")

# This functions checks / iterates through every object in array, then returns existing groupname
# Function to determine the correct admin group
def determine_admin_group():
admin_groups = ["Administrateurs", "Administratoren", "Administrators"]
for group in admin_groups:
Expand All @@ -53,14 +66,28 @@ def determine_admin_group():
return group
return None

root = customtkinter.CTk()
def success_message(message):
message_label = customtkinter.CTkLabel(root, text=message, font=('Bold Calibri', 10), text_color="green")
message_label.place(relx=0.1, rely=0.875, relwidth=0.8)

# Create Window for GUI and add Icon
def error_message(message):
message_label = customtkinter.CTkLabel(root, text=message, font=('Bold Calibri', 10), text_color="red")
message_label.place(relx=0.1, rely=0.875, relwidth=0.8)

# Function to check if the program is running as administrator
def run_as_admin():
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False

# Initialize main application window
root = customtkinter.CTk()
root.title('Offline Account Creator')
root.geometry('350x350')
root.resizable(False, False)

# Title Account Creator centered
# Title label
title = customtkinter.CTkLabel(root, text="Account Creator", font=('Bold Calibri', 25))
title.place(relx=0.25, rely=0.1)

Expand All @@ -69,20 +96,19 @@ def determine_admin_group():
username.place(relx=0.3, rely=0.3)

# Entry for Password
password = customtkinter.CTkEntry(root, corner_radius=10, width=140, height=40, fg_color="#ffffff", text_color="#000000", placeholder_text="Password")
password.configure(show="*")
password = customtkinter.CTkEntry(root, corner_radius=10, width=140, height=40, fg_color="#ffffff", text_color="#000000", placeholder_text="Password", show="*")
password.place(relx=0.3, rely=0.45)

# Checkbox if admin is needed
# Checkbox for admin privilege
admin_check_var = BooleanVar()
admin_check = customtkinter.CTkCheckBox(root, corner_radius=10, fg_color="#ffffff", checkmark_color="#000000", text="Administrator", variable=admin_check_var)
admin_check.place(relx=0.35, rely=0.625)

# Function so that the button press works -> linked in command
# Function to handle submit button press
def submit_pressed():
create_account()

# Submit button, linked with submit_pressed function
# Submit button
submit = customtkinter.CTkButton(root, corner_radius=10, text="Submit", fg_color="#ffffff", hover_color="#A9A9A9", text_color="#000000", command=submit_pressed)
submit.place(relx=0.5, rely=0.8, anchor=customtkinter.CENTER)

Expand Down

0 comments on commit 236fde7

Please sign in to comment.