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