default username and password

This commit is contained in:
Ingolf Wagner 2024-11-17 07:06:32 +07:00
parent 830f04d710
commit eff7d1c887
No known key found for this signature in database
GPG key ID: 76BF5F1928B9618B

View file

@ -7,6 +7,8 @@ import http.server
import socket import socket
import socketserver import socketserver
import qrcode import qrcode
import random
import string
def get_current_ip_address(): def get_current_ip_address():
@ -17,24 +19,50 @@ def get_current_ip_address():
return ip_address return ip_address
# Function to generate a default username
def generate_default_username():
return "user_" + "".join(
random.choices(string.ascii_lowercase + string.digits, k=8)
)
# Function to generate a default password
def generate_default_password():
return "".join(
random.choices(string.ascii_letters + string.digits + string.punctuation, k=12)
)
# Define the command-line arguments # Define the command-line arguments
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description="Start a simple HTTP server with basic authentication." description="Start a simple HTTP server with basic authentication."
) )
parser.add_argument( parser.add_argument(
"--port", type=int, default=8000, help="Port to serve the directory over." "--port",
type=int,
default=8000,
help="Port to serve the directory over. Defaults to 8000.",
) )
parser.add_argument( parser.add_argument(
"--username", required=True, help="Username for basic authentication." "--username",
default=generate_default_username(),
help="Username for basic authentication. Generates one if not set",
) )
parser.add_argument( parser.add_argument(
"--password", required=True, help="Password for basic authentication." "--password",
default=generate_default_password(),
help="Password for basic authentication. Generates one if not set",
) )
parser.add_argument( parser.add_argument(
"--directory", "--directory",
default=os.getcwd(), default=os.getcwd(),
help="Directory to serve. Defaults to the current directory.", help="Directory to serve. Defaults to the current directory.",
) )
args = parser.parse_args() args = parser.parse_args()
# Expand the directory path (e.g., if it contains ~) # Expand the directory path (e.g., if it contains ~)