3 * Change the password of a given user
5 * @addtogroup Maintenance
7 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
8 * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
9 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
12 $optionsWithArgs = array( 'user', 'password' );
13 require_once 'commandLine.inc';
16 "Usage: php changePassword.php [--user=user --password=password | --help]\n" .
18 "\t\t--help show this message\n" .
19 "\t\t--user the username to operate on\n" .
20 "\t\t--password the password to use\n";
22 if( in_array( '--help', $argv ) )
25 $cp = new ChangePassword( @$options['user'], @$options['password'] );
28 class ChangePassword
{
32 function ChangePassword( $user, $password ) {
34 if( !strlen( $user ) or !strlen( $password ) ) {
38 $this->user
= User
::newFromName( $user );
39 if ( !$this->user
->getID() ) {
40 die ( "No such user: $user\n" );
43 $this->password
= $password;
45 $this->dbw
= wfGetDB( DB_MASTER
);
49 $fname = 'ChangePassword::main';
51 $this->dbw
->update( 'user',
53 'user_password' => wfEncryptPassword( $this->user
->getID(), $this->password
)
56 'user_id' => $this->user
->getID()