Skip to content

Instantly share code, notes, and snippets.

@xeoncross
Last active June 12, 2019 01:17
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xeoncross/4526844 to your computer and use it in GitHub Desktop.
Save xeoncross/4526844 to your computer and use it in GitHub Desktop.
Vanilla Forums CLI Password Reset Script

VanillaForums Password Reset

A command line (CLI) password reset script. Simply give it a username and a new password and it will change it for you. Completely safe to have in the web root since it only allows access from the CLI. Not safe on servers were other untrusted users have access to your forum code (why are they on the server anyway?)

Usage

$ php password_reset.php Bob anewpassword

If no password is given, a random password is created and used.

$ php password_reset.php Bob
  The password for Bob has been changed to "63b102d5"
$ ...
<?php PHP_SAPI == 'cli' OR die('CLI use only');
// We need a username here folks
if(empty($argv[1]))
{
die('Usage: $ php ' . basename(__FILE__) . " [username] [password]\n");
}
define('APPLICATION', 'Vanilla');
// Report and track all errors.
error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR);
ini_set('display_errors', 'on');
ini_set('track_errors', 1);
// Define the constants we need to get going.
define('DS', '/');
define('PATH_ROOT', getcwd());
// Include the bootstrap to configure the framework.
require_once(PATH_ROOT.'/bootstrap.php');
// The username and password are passed in from the command line arguments
$user = $argv[1];
$password = isset($argv[2]) ? $argv[2] : substr(sha1(mt_rand() . uniqid(true)), 0, 8);
$PasswordHash = new Gdn_PasswordHash();
$sql = 'UPDATE `GDN_User` SET `Password` = :Password WHERE `GDN_User`.`Name` = :UserName';
$PDOStatement = Gdn::Database()->Connection()->prepare($sql);
$PDOStatement->execute(array(
':Password' => $PasswordHash->HashPassword($password),
':UserName' => $user
));
if($PDOStatement->rowCount())
{
print "The password for $user has been changed to \"$password\"\n"
. $PasswordHash->HashPassword($password) . "\n";
}
else
{
print "Username \"$user\" not found\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment