From a24ba286304ef091de651098da0f08956d719a54 Mon Sep 17 00:00:00 2001 From: Esenjin Date: Mon, 30 Dec 2024 20:17:27 +0100 Subject: [PATCH] =?UTF-8?q?ajout=20fichier=20de=20cr=C3=A9ation=20de=20la?= =?UTF-8?q?=20bdd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- init-db-php.php | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 init-db-php.php diff --git a/init-db-php.php b/init-db-php.php new file mode 100644 index 0000000..a54f894 --- /dev/null +++ b/init-db-php.php @@ -0,0 +1,41 @@ +exec('CREATE TABLE IF NOT EXISTS admins ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + username TEXT UNIQUE NOT NULL, + password_hash TEXT NOT NULL, + created_at DATETIME DEFAULT CURRENT_TIMESTAMP +)'); + +// Créer la table des albums protégés +$db->exec('CREATE TABLE IF NOT EXISTS protected_albums ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + path TEXT UNIQUE NOT NULL, + password_hash TEXT NOT NULL, + created_at DATETIME DEFAULT CURRENT_TIMESTAMP +)'); + +// Insérer un admin par défaut si la table est vide +$result = $db->query('SELECT COUNT(*) as count FROM admins'); +$count = $result->fetchArray()['count']; + +if ($count === 0) { + // Créer un admin par défaut (admin/admin) - À changer après la première connexion ! + $default_username = 'admin'; + $default_password = 'admin'; + $password_hash = password_hash($default_password, PASSWORD_DEFAULT); + + $stmt = $db->prepare('INSERT INTO admins (username, password_hash) VALUES (:username, :password_hash)'); + $stmt->bindValue(':username', $default_username, SQLITE3_TEXT); + $stmt->bindValue(':password_hash', $password_hash, SQLITE3_TEXT); + $stmt->execute(); + + echo "Admin par défaut créé (username: admin, password: admin). Pensez à changer ces identifiants !"; +} + +$db->close(); +echo "Base de données initialisée avec succès !"; +?> \ No newline at end of file