Debian Codegraph @

maintenance/changePassword.php

raw symbols SCIP
1 <?php
2 /**
3 * Change the password of a given user
4 *
5 * Copyright © 2005, Ævar Arnfjörð Bjarmason
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
21 *
22 * @file
23 * @author Ævar Arnfjörð Bjarmason <[email protected]om>
24 * @ingroup Maintenance
25 */
26
27 // @codeCoverageIgnoreStart
28 require_once __DIR__ . '/Maintenance.php';
29 // @codeCoverageIgnoreEnd
30
31 use MediaWiki\Logger\LoggerFactory;
32 use MediaWiki\Maintenance\Maintenance;
33
34 /**
35 * Maintenance script to change the password of a given user.
36 *
37 * @ingroup Maintenance
38 */
39 class ChangePassword extends Maintenance {
40 public function __construct() {
41 parent::__construct();
42 $this->addOption( "user", "The username to operate on", false, true );
43 $this->addOption( "userid", "The user id to operate on", false, true );
44 $this->addOption( "password", "The password to use", true, true );
45 $this->addOption( 'reason', 'Reason for the password change (ticket number etc)', false, true );
46 $this->addDescription( "Change a user's password" );
47 }
48
49 public function execute() {
50 $user = $this->validateUserOption( "A \"user\" or \"userid\" must be set to change the password for" );
51 $password = $this->getOption( 'password' );
52 $status = $user->changeAuthenticationData( [
53 'username' => $user->getName(),
54 'password' => $password,
55 'retype' => $password,
56 ] );
57 if ( $status->isGood() ) {
58 $this->output( "Password set for " . $user->getName() . "\n" );
59
60 LoggerFactory::getInstance( 'authentication' )->info(
61 'Password for {user} changed via changePassword.php', [
62 'user' => $user->getName(),
63 'reason' => $this->getOption( 'reason', '' ),
64 ]
65 );
66
67 $invalidator = $this->createChild( InvalidateUserSessions::class );
68 $invalidator->setOption( 'user', $user->getName() );
69 $invalidator->execute();
70 } else {
71 $this->fatalError( $status );
72 }
73 }
74 }
75
76 // @codeCoverageIgnoreStart
77 $maintClass = ChangePassword::class;
78 require_once RUN_MAINTENANCE_IF_MAIN;
79 // @codeCoverageIgnoreEnd