]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - maintenance/changePassword.php
MediaWiki 1.14.0-scripts
[autoinstallsdev/mediawiki.git] / maintenance / changePassword.php
1 <?php
2 /**
3  * Change the password of a given user
4  *
5  * @file
6  * @ingroup Maintenance
7  *
8  * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
9  * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
10  * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
11  */
12
13 $optionsWithArgs = array( 'user', 'password' );
14 require_once 'commandLine.inc';
15
16 $USAGE = 
17         "Usage: php changePassword.php [--user=user --password=password | --help]\n" .
18         "\toptions:\n" .
19         "\t\t--help      show this message\n" .
20         "\t\t--user      the username to operate on\n" .
21         "\t\t--password  the password to use\n";
22
23 if( in_array( '--help', $argv ) )
24         wfDie( $USAGE );
25
26 $cp = new ChangePassword( @$options['user'], @$options['password'] );
27 $cp->main();
28
29 /**
30  * @ingroup Maintenance
31  */
32 class ChangePassword {
33         var $dbw;
34         var $user, $password;
35
36         function ChangePassword( $user, $password ) {
37                 global $USAGE;
38                 if( !strlen( $user ) or !strlen( $password ) ) {
39                         wfDie( $USAGE );
40                 }
41
42                 $this->user = User::newFromName( $user );
43                 if ( !$this->user->getId() ) {
44                         die ( "No such user: $user\n" );
45                 }
46
47                 $this->password = $password;
48
49                 $this->dbw = wfGetDB( DB_MASTER );
50         }
51
52         function main() {
53                 $fname = 'ChangePassword::main';
54
55                 $this->user->setPassword( $this->password );
56                 $this->user->saveSettings();
57         }
58 }