X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FchangePassword.php;h=0fe8c0bea3e1d7510ee4be9bc022c90dae20e88b;hb=7d334366a13e7f481325acf7d6c514ba0d8f0fb2;hp=526feb798691e036a9781bcebd3047b693c370ca;hpb=a0ad70ecbda4a35c81912e2fd7e9e2e9f6357a6c;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/changePassword.php b/maintenance/changePassword.php index 526feb7986..0fe8c0bea3 100644 --- a/maintenance/changePassword.php +++ b/maintenance/changePassword.php @@ -2,51 +2,55 @@ /** * Change the password of a given user * - * @package MediaWiki - * @subpackage Maintenance + * @file + * @ingroup Maintenance * * @author Ævar Arnfjörð Bjarmason * @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(); + +/** + * @ingroup Maintenance + */ 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 ); + + $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 - ); + $this->user->setPassword( $this->password ); + $this->user->saveSettings(); } } - -$optionsWithArgs = array( 'user', 'password' ); -require_once 'commandLine.inc'; - -if( in_array( '--help', $argv ) ) - die( - "Usage: php changePassword.php [--user=user --password=password | --help]\n" . - "\toptions:\n" . - "\t\t--help\tshow this message\n" . - "\t\t--user\tthe username to operate on\n" . - "\t\t--password\tthe password to use\n" - ); - -$cp = new ChangePassword( @$options['user'], @$options['password'] ); -$cp->main();