Passwort hashen
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user