Remove ?>'s from files. They're pointless, and just asking for people to mess with...
[lhc/web/wiklou.git] / maintenance / changePassword.php
1 <?php
2 /**
3 * Change the password of a given user
4 *
5 * @addtogroup Maintenance
6 *
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
10 */
11
12 $optionsWithArgs = array( 'user', 'password' );
13 require_once 'commandLine.inc';
14
15 $USAGE =
16 "Usage: php changePassword.php [--user=user --password=password | --help]\n" .
17 "\toptions:\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";
21
22 if( in_array( '--help', $argv ) )
23 wfDie( $USAGE );
24
25 $cp = new ChangePassword( @$options['user'], @$options['password'] );
26 $cp->main();
27
28 class ChangePassword {
29 var $dbw;
30 var $user, $password;
31
32 function ChangePassword( $user, $password ) {
33 global $USAGE;
34 if( !strlen( $user ) or !strlen( $password ) ) {
35 wfDie( $USAGE );
36 }
37
38 $this->user = User::newFromName( $user );
39 if ( !$this->user->getID() ) {
40 die ( "No such user: $user\n" );
41 }
42
43 $this->password = $password;
44
45 $this->dbw = wfGetDB( DB_MASTER );
46 }
47
48 function main() {
49 $fname = 'ChangePassword::main';
50
51 $this->dbw->update( 'user',
52 array(
53 'user_password' => wfEncryptPassword( $this->user->getID(), $this->password )
54 ),
55 array(
56 'user_id' => $this->user->getID()
57 ),
58 $fname
59 );
60 }
61 }
62
63