"""Erstellt die initialen Nutzer für den OSINT Lagemonitor.""" import asyncio import os import sys import secrets import string sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src")) from database import init_db, get_db from auth import hash_password def generate_password(length=16): """Generiert ein sicheres Passwort.""" alphabet = string.ascii_letters + string.digits + "!@#$%&*" return ''.join(secrets.choice(alphabet) for _ in range(length)) async def main(): await init_db() db = await get_db() users = [ {"username": "rac00n", "password": generate_password()}, {"username": "ch33tah", "password": generate_password()}, ] print("\n=== OSINT Lagemonitor - Nutzer-Setup ===\n") for user in users: cursor = await db.execute( "SELECT id FROM users WHERE username = ?", (user["username"],) ) existing = await cursor.fetchone() if existing: # Passwort aktualisieren pw_hash = hash_password(user["password"]) await db.execute( "UPDATE users SET password_hash = ? WHERE username = ?", (pw_hash, user["username"]), ) print(f" Nutzer '{user['username']}' - Passwort aktualisiert") else: pw_hash = hash_password(user["password"]) await db.execute( "INSERT INTO users (username, password_hash) VALUES (?, ?)", (user["username"], pw_hash), ) print(f" Nutzer '{user['username']}' - Erstellt") print(f" Passwort: {user['password']}") print() await db.commit() await db.close() print("WICHTIG: Passwörter jetzt notieren! Sie werden nicht erneut angezeigt.\n") if __name__ == "__main__": asyncio.run(main())