. */ require_once realpath(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'bootstrap.php'); use nntmux\db\Settings; use nntmux\ColorCLI; use nntmux\Users; $colorCLI = new ColorCLI(); $warning = <<warning($warning); if ($argc != 2) { exit($colorCLI->error("\nWrong number of parameters$usage")); } else if ($argv[1] !== 1 && $argv[1] != '' && $argv[1] != 'IUnderStandTheRisks' && $argv[1] != 'true') { exit($colorCLI->error("\nInvalid parameter(s)$usage")); } $pdo = new Settings(); $users = $pdo->query("SELECT id, username, email, password FROM users"); $update = $pdo->Prepare('UPDATE users SET password = :password WHERE id = :id'); $Users = new Users(['Settings' => $pdo]); foreach ($users as $user) { if (needUpdate($user)) { $hash = $Users->hashPassword($user['email']); if ($hash !== false) { $update->execute([':password' => $hash, ':id' => $user['id']]); echo $colorCLI->primary('Updating hash for user:') . $user['username']; } else { echo $colorCLI->error('Error updating hash for user:') . $user['username']; } } } function needUpdate($user) { global $colorCLI; $status = true; if (empty($user['email'])) { $status = false; echo $colorCLI->error('Cannot update password hash - Email is not set for user: ' . $user['username']); } else if (preg_match('#^\$.+$#', $user['password'])) { $status = false; echo $user['username'] . $colorCLI->primary(' is already using new style hash ;-)'); } return $status; }