Skip to content

Instantly share code, notes, and snippets.

@dregad
Created May 10, 2026 16:55
Show Gist options
  • Select an option

  • Save dregad/e082ab2cecfd37e5320043effbff230c to your computer and use it in GitHub Desktop.

Select an option

Save dregad/e082ab2cecfd37e5320043effbff230c to your computer and use it in GitHub Desktop.
MantisBT script to reset all users' passwords
<?php
// Specify username and password to use
$t_username = 'administrator';
$t_password = 'root';
use Mantis\Exceptions\ClientException;
require_once( dirname( __DIR__ ) . '/core.php' );
$t_query = new DbQuery( 'SELECT id, username FROM {user}' );
//$t_query->append_sql( ' WHERE id = 1234' );
auth_attempt_script_login( $t_username, $t_password );
echo "Resetting user passwords\n";
echo "Logged-in as '", current_user_get_field('username'), "'\n\n";
echo "ID Username Result\n";
echo "----- -------------------- ------\n";
foreach( $t_query->execute() as $t_user ) {
extract( $t_user, EXTR_PREFIX_ALL, 'v' );
vprintf( "%5d %-20s ", $t_user );
$t_data = array(
'query' => array( 'id' => $v_id )
);
$t_command = new UserResetPasswordCommand( $t_data );
try {
$t_result = $t_command->execute();
echo $t_result != UserResetPasswordCommand::RESULT_RESET ? 'OK' : 'FAILED', PHP_EOL;
}
catch( ClientException $e ) {
echo $e->getMessage(), PHP_EOL;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment