コード例 #1
0
ファイル: setUserPasswordHash.php プロジェクト: sebst3r/nZEDb
 * Hopefully that will allow admin access to fix any further problems.
 */
require_once dirname(__FILE__) . '/../../../www/config.php';
use nzedb\Users;
use nzedb\db\Settings;
$pdo = new Settings();
if ($argc < 3) {
    exit($pdo->log->error('Not enough parameters!' . PHP_EOL . 'Argument 1: New password.' . PHP_EOL . 'Argument 2: ID or username of the user.' . PHP_EOL));
}
$password = $argv[1];
$identifier = $argv[2];
if (is_numeric($password)) {
    exit($pdo->log->error('Password cannot be numbers only!'));
}
$field = is_numeric($identifier) ? 'id' : 'username';
$user = $pdo->queryOneRow(sprintf("SELECT id, username FROM users WHERE %s = %s", $field, is_numeric($identifier) ? $identifier : $pdo->escapeString($identifier)));
if ($user !== false) {
    $users = new Users(['Settings' => $pdo]);
    $hash = $users->hashPassword($password);
    $result = false;
    if ($hash !== false) {
        $hash = $pdo->queryExec(sprintf('UPDATE users SET password = %s WHERE id = %d', $hash, $user['id']));
    }
    if ($result === false || $hash === false) {
        echo $pdo->log->error('An error occured during update attempt.' . PHP_EOL . $pdo->errorInfo());
    } else {
        echo $pdo->log->headerOver("Updated {$user['username']}'s password hash to: ") . $pdo->log->primary("{$hash}");
    }
} else {
    echo $pdo->log->error("Unable to find {$field} '{$identifier}' in the users. Cannot change password.");
}
コード例 #2
0
$usage = "\nUsage: php {$argv[0]} <IUnderStandTheRisks>";
echo $colorCLI->warning($warning);
if ($argc != 2) {
    exit($colorCLI->error("\nWrong number of parameters{$usage}"));
} else {
    if ($argv[1] !== 1 && $argv[1] != '<IUnderStandTheRisks>' && $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:'******'username'];
        } else {
            echo $colorCLI->error('Error updating hash for 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: '******'username']);