* Hash un mot de passe fourni et met à jour database.json */ if (php_sapi_name() !== 'cli') { die("Ce script doit être exécuté en ligne de commande.\n"); } if ($argc < 3) { echo "Usage : php set_password.php \n"; echo "Exemple : php set_password.php Demo_01 MonMotDePasse123\n"; exit(1); } $client_id = $argv[1]; $password = $argv[2]; $json_file = dirname(__DIR__) . '/database.json'; if (!file_exists($json_file)) { die("Erreur : database.json introuvable\n"); } $db = json_decode(file_get_contents($json_file), true); // Recherche du client $client_index = -1; if (isset($db['clients'])) { foreach ($db['clients'] as $index => $c) { if (strcasecmp($c['name'], $client_id) == 0) { $client_index = $index; break; } } } if ($client_index === -1) { die("Erreur : Client '$client_id' introuvable dans la base de données\n"); } // Hash du mot de passe $password_hash = password_hash($password, PASSWORD_BCRYPT); // Mise à jour de la base $db['clients'][$client_index]['password_hash'] = $password_hash; file_put_contents($json_file, json_encode($db, JSON_PRETTY_PRINT)); // Affichage echo "✅ Mot de passe défini avec succès pour '$client_id'\n"; echo " Le hash bcrypt a été enregistré dans database.json\n\n"; ?>