Skip to content

Instantly share code, notes, and snippets.

@debloper
Last active April 17, 2023 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save debloper/b0d96f5fcf4a186339d7acd3779a70d4 to your computer and use it in GitHub Desktop.
Save debloper/b0d96f5fcf4a186339d7acd3779a70d4 to your computer and use it in GitHub Desktop.
Update/reset mediawiki password for a user directly in SQLite DB without SUDO (NFSN/nearlyfreespeech.net edge case)
<?php
// Replace <DB> with actual DB name
$db = new PDO("sqlite:/path/to/<DB>.sqlite") or die("cannot open the database");
// The WHERE clause excludes internal users; feel free to filter it any way you want
$query = $db->query("SELECT * FROM user WHERE user_email <> '';");
// Get the column names; unfortunately this is the simplest way
$meta = "";
for ($i=0; $i<=7; $i++) { $meta = $meta . "\n" . $query->getColumnMeta($i)["name"]; }
echo "<pre>".$meta."</pre>";
// Format & list the query results
foreach($query as $row) { echo "<pre>".implode("\n", $row)."</pre>"; }
// Close DB connection
$db = null;
?>
<?php
// Replace <DB> with actual DB name
$db = new PDO("sqlite:/path/to/<DB>.sqlite") or die("cannot open the database");
// Replace <SET_KNOWN_HASH> & <USER_EMAIL> with actual values
$query = $db->query("UPDATE user SET user_password = '<SET_KNOWN_HASH>', user_newpassword = '', user_newpass_time = '' WHERE user_email = '<USER_EMAIL>';");
// Close DB connection
$db = null;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment