Passwort hashen

This commit is contained in:
Nirodan
2025-06-16 10:24:54 +02:00
parent eb674efe9a
commit 492bc31393
3 changed files with 15 additions and 11 deletions
+5 -5
View File
@@ -1,5 +1,7 @@
import json
import mysql.connector
from werkzeug.security import generate_password_hash
def lade_db_config(pfad='config/db_config.json'):
with open(pfad, 'r') as f:
@@ -19,11 +21,9 @@ def teste_verbindung(db_config):
return False
def initialisiere_admin_user(db_config):
import mysql.connector
conn = mysql.connector.connect(**db_config)
cursor = conn.cursor()
# Tabelle erstellen, falls nicht vorhanden
cursor.execute("""
CREATE TABLE IF NOT EXISTS users (
id INT AUTO_INCREMENT PRIMARY KEY,
@@ -33,14 +33,14 @@ def initialisiere_admin_user(db_config):
)
""")
# Prüfen, ob admin existiert
cursor.execute("SELECT id FROM users WHERE username = 'admin'")
if not cursor.fetchone():
hashed_pw = generate_password_hash('admin')
cursor.execute("""
INSERT INTO users (username, password, role)
VALUES (%s, %s, 'admin')
""", ('admin', 'admin'))
print("[INFO] Admin-Account wurde erstellt: admin / admin")
""", ('admin', hashed_pw))
print("[INFO] Admin-Account wurde erstellt (gehashed): admin / admin")
conn.commit()
cursor.close()