3 * Change the password of a given user
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
13 require_once( "Maintenance.php" );
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."
23 public function execute() {
24 if( !$this->hasOption('user') ||
!$this->hasOption('password') ) {
25 $this->error( "Username or password not provided, halting.", true );
27 $user = User
::newFromName( $this->getOption('user') );
28 if( !$user->getId() ) {
29 $this->error( "No such user: " . $this->getOption('user') . "\n", true );
32 $user->setPassword( $this->getOption('password') );
33 $user->saveSettings();
34 } catch( PasswordError
$pwe ) {
35 $this->error( $pwe->getText(), true );
40 $maintClass = "ChangePassword";
41 require_once( DO_MAINTENANCE
);