* Password changing script for idiot users with amnesia
[lhc/web/wiklou.git] / maintenance / changePassword.php
1 <?php
2 /**
3 * Change the password of a given user
4 *
5 * @package MediaWiki
6 * @subpackage 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 class ChangePassword {
14 var $dbw;
15 var $user, $password;
16
17 function ChangePassword( $user, $password ) {
18 $this->user = User::newFromName( $user );
19 $this->password = $password;
20
21 $this->dbw =& wfGetDB( DB_MASTER );
22 }
23
24 function main() {
25 $fname = 'ChangePassword::main';
26
27 $this->dbw->update( 'user',
28 array(
29 'user_password' => wfEncryptPassword( $this->user->getID(), $this->password )
30 ),
31 array(
32 'user_id' => $this->user->getID()
33 ),
34 $fname
35 );
36 }
37 }
38 if ( in_array( '--help', $argv ) )
39 die(
40 "Usage: php changePassword.php [--user=user --password=password | --help]\n" .
41 "\toptions:\n" .
42 "\t\t--help\tshow this message\n" .
43 "\t\t--user\tthe username to operate on\n" .
44 "\t\t--password\tthe password to use\n"
45 );
46
47 $optionsWithArgs = array( 'user', 'password' );
48 require_once 'commandLine.inc';
49
50 $cp = new ChangePassword( @$options['user'], @$options['password'] );
51 $cp->main();