006562a06f501fcb56e322f18813e7ee13f2ccf2
[lhc/web/wiklou.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 require_once( "Maintenance.php" );
14
15 class ChangePassword extends Maintenance {
16 public function __construct() {
17 parent::__construct();
18 $this->addParam( "user", "The username to operate on", true, true );
19 $this->addParam( "password", "The password to use", true, true );
20 $this->mDescription = "Change a user's password."
21 }
22
23 public function execute() {
24 if( !$this->hasOption('user') || !$this->hasOption('password') ) {
25 $this->error( "Username or password not provided, halting.", true );
26 }
27 $user = User::newFromName( $this->getOption('user') );
28 if( !$user->getId() ) {
29 $this->error( "No such user: " . $this->getOption('user') . "\n", true );
30 }
31 try {
32 $user->setPassword( $this->getOption('password') );
33 $user->saveSettings();
34 } catch( PasswordError $pwe ) {
35 $this->error( $pwe->getText(), true );
36 }
37 }
38 }
39
40 $maintClass = "ChangePassword";
41 require_once( DO_MAINTENANCE );