From 78c13051d04aadea2415c743159f636766e61558 Mon Sep 17 00:00:00 2001 From: "Manuel Weiser (aider)" Date: Mon, 2 Sep 2024 10:45:58 +0200 Subject: [PATCH] feat: create default admin user when initializing the database --- game_collection/database.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/game_collection/database.py b/game_collection/database.py index 8e24570..bc9a147 100644 --- a/game_collection/database.py +++ b/game_collection/database.py @@ -1,6 +1,7 @@ import sqlite3 import os from flask import current_app +from werkzeug.security import generate_password_hash def init_db(): db_path = os.path.join(current_app.instance_path, 'games.db') @@ -30,5 +31,12 @@ def init_db(): ) ''') + # Standardbenutzer erstellen + hashed_password = generate_password_hash("admin") + cursor.execute(''' + INSERT OR IGNORE INTO users (username, password, role) + VALUES (?, ?, ?) + ''', ("admin", hashed_password, "admin")) + conn.commit() conn.close()