r47569 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47568‎ | r47569 | r47570 >
Date:18:35, 20 February 2009
Author:demon
Status:reverted (Comments)
Tags:
Comment:
ChangePassword fixes:
* (bug 15876) Allow on-wiki password resets. Needs 'reset-passwords' right, given by default to nobody (commented in DefaultSettings)
* Stronger username checking. If we're not allowed to change other people's passwords, don't even attempt it
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/User.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialResetpass.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -461,6 +461,7 @@
462462 'resetpass-submit-loggedin',
463463 'resetpass-wrong-oldpass',
464464 'resetpass-temp-password',
 465+ 'resetpass-no-others',
465466 ),
466467 'toolbar' => array(
467468 'bold_sample',
Index: trunk/phase3/includes/User.php
@@ -162,6 +162,7 @@
163163 'proxyunbannable',
164164 'purge',
165165 'read',
 166+ 'reset-passwords',
166167 'reupload',
167168 'reupload-shared',
168169 'rollback',
Index: trunk/phase3/includes/DefaultSettings.php
@@ -1255,6 +1255,8 @@
12561256 // Permission to change users' group assignments
12571257 $wgGroupPermissions['bureaucrat']['userrights'] = true;
12581258 $wgGroupPermissions['bureaucrat']['noratelimit'] = true;
 1259+// Permission to change users' passwords
 1260+# $wgGroupPermissions['bureaucrat']['reset-passwords'] = true;
12591261 // Permission to change users' groups assignments across wikis
12601262 #$wgGroupPermissions['bureaucrat']['userrights-interwiki'] = true;
12611263
Index: trunk/phase3/includes/specials/SpecialResetpass.php
@@ -9,6 +9,9 @@
1010 * @ingroup SpecialPage
1111 */
1212 class SpecialResetpass extends SpecialPage {
 13+
 14+ private $mSelfChange = true; // Usually, but sometimes not :)
 15+
1316 public function __construct() {
1417 parent::__construct( 'Resetpass' );
1518 }
@@ -19,7 +22,7 @@
2023 function execute( $par ) {
2124 global $wgUser, $wgAuth, $wgOut, $wgRequest;
2225
23 - $this->mUserName = $wgRequest->getVal( 'wpName' );
 26+ $this->mUserName = $wgRequest->getVal( 'wpName', $par );
2427 $this->mOldpass = $wgRequest->getVal( 'wpPassword' );
2528 $this->mNewpass = $wgRequest->getVal( 'wpNewPassword' );
2629 $this->mRetype = $wgRequest->getVal( 'wpRetype' );
@@ -31,17 +34,33 @@
3235 $this->error( wfMsg( 'resetpass_forbidden' ) );
3336 return;
3437 }
 38+
 39+ // Default to our own username when not given one
 40+ if ( !$this->mUserName ) {
 41+ $this->mUserName = $wgUser->getName();
 42+ }
 43+
 44+ // Are we changing our own?
 45+ if ( $wgUser->getName() != $this->mUserName ) {
 46+ $this->mSelfChange = false; // We're changing someone else
 47+ }
3548
3649 if( !$wgRequest->wasPosted() && !$wgUser->isLoggedIn() ) {
3750 $this->error( wfMsg( 'resetpass-no-info' ) );
3851 return;
3952 }
4053
 54+ if ( !$this->mSelfChange && !$wgUser->isAllowed( 'reset-passwords' ) ) {
 55+ $this->error( wfMsg( 'resetpass-no-others' ) );
 56+ return;
 57+ }
 58+
4159 if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal('token') ) ) {
4260 try {
4361 $this->attemptReset( $this->mNewpass, $this->mRetype );
4462 $wgOut->addWikiMsg( 'resetpass_success' );
45 - if( !$wgUser->isLoggedIn() ) {
 63+ // Only attempt this login session if we're changing our own password
 64+ if( $this->mSelfChange && !$wgUser->isLoggedIn() ) {
4665 $data = array(
4766 'action' => 'submitlogin',
4867 'wpName' => $this->mUserName,
@@ -77,9 +96,7 @@
7897 $wgOut->disallowUserJs();
7998
8099 $self = SpecialPage::getTitleFor( 'Resetpass' );
81 - if ( !$this->mUserName ) {
82 - $this->mUserName = $wgUser->getName();
83 - }
 100+
84101 $rememberMe = '';
85102 if ( !$wgUser->isLoggedIn() ) {
86103 $rememberMe = '<tr>' .
@@ -104,15 +121,14 @@
105122 'action' => $self->getLocalUrl(),
106123 'id' => 'mw-resetpass-form' ) ) .
107124 Xml::hidden( 'token', $wgUser->editToken() ) .
108 - Xml::hidden( 'wpName', $this->mUserName ) .
109125 Xml::hidden( 'returnto', $wgRequest->getVal( 'returnto' ) ) .
110126 wfMsgExt( 'resetpass_text', array( 'parse' ) ) .
111127 Xml::openElement( 'table', array( 'id' => 'mw-resetpass-table' ) ) .
112128 $this->pretty( array(
113 - array( 'wpName', 'username', 'text', $this->mUserName ),
114 - array( 'wpPassword', $oldpassMsg, 'password', $this->mOldpass ),
115 - array( 'wpNewPassword', 'newpassword', 'password', '' ),
116 - array( 'wpRetype', 'retypenew', 'password', '' ),
 129+ array( 'wpName', 'username', 'text', $this->mUserName, !$this->mSelfChange ),
 130+ array( 'wpPassword', $oldpassMsg, 'password', $this->mOldpass, $this->mSelfChange ),
 131+ array( 'wpNewPassword', 'newpassword', 'password', '', true ),
 132+ array( 'wpRetype', 'retypenew', 'password', '', true ),
117133 ) ) .
118134 $rememberMe .
119135 '<tr>' .
@@ -130,21 +146,16 @@
131147 function pretty( $fields ) {
132148 $out = '';
133149 foreach( $fields as $list ) {
134 - list( $name, $label, $type, $value ) = $list;
135 - if( $type == 'text' ) {
136 - $field = htmlspecialchars( $value );
137 - } else {
138 - $field = Xml::input( $name, 20, $value,
139 - array( 'id' => $name, 'type' => $type ) );
140 - }
 150+ list( $name, $label, $type, $value, $enabled ) = $list;
 151+ $params = array( 'id' => $name, 'type' => $type );
 152+ if ( !$enabled )
 153+ $params['disabled'] = 'disabled';
 154+ $field = Xml::input( $name, 20, $value, $params );
141155 $out .= '<tr>';
142 - $out .= "<td class='mw-label'>";
143 - if ( $type != 'text' )
144 - $out .= Xml::label( wfMsg( $label ), $name );
145 - else
146 - $out .= wfMsg( $label );
 156+ $out .= '<td class="mw-label">';
 157+ $out .= Xml::label( wfMsg( $label ), $name );
147158 $out .= '</td>';
148 - $out .= "<td class='mw-input'>";
 159+ $out .= '<td class="mw-input">';
149160 $out .= $field;
150161 $out .= '</td>';
151162 $out .= '</tr>';
@@ -166,9 +177,11 @@
167178 throw new PasswordError( wfMsg( 'badretype' ) );
168179 }
169180
170 - if( !$user->checkTemporaryPassword($this->mOldpass) && !$user->checkPassword($this->mOldpass) ) {
171 - wfRunHooks( 'PrefsPasswordAudit', array( $user, $newpass, 'wrongpassword' ) );
172 - throw new PasswordError( wfMsg( 'resetpass-wrong-oldpass' ) );
 181+ if ( $this->mSelfChange ) {
 182+ if( !$user->checkTemporaryPassword($this->mOldpass) && !$user->checkPassword($this->mOldpass) ) {
 183+ wfRunHooks( 'PrefsPasswordAudit', array( $user, $newpass, 'wrongpassword' ) );
 184+ throw new PasswordError( wfMsg( 'resetpass-wrong-oldpass' ) );
 185+ }
173186 }
174187
175188 try {
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -1016,6 +1016,7 @@
10171017 'resetpass-wrong-oldpass' => 'Invalid temporary or current password.
10181018 You may have already successfully changed your password or requested a new temporary password.',
10191019 'resetpass-temp-password' => 'Temporary password:',
 1020+'resetpass-no-others' => 'You cannot reset the password for other users.',
10201021
10211022 # Edit page toolbar
10221023 'bold_sample' => 'Bold text',
Index: trunk/phase3/RELEASE-NOTES
@@ -113,6 +113,8 @@
114114 * Special:ListUsers: Sort list of usergroups by alphabet
115115 * (bug 16762) Special:Movepage now shows a list of subpages when possible
116116 * (bug 17585) Hide legend on Special:Specialpages from non-privileged users
 117+* (bug 15876) Users with 'reset-passwords' right can change the passwords of
 118+ other users.
117119
118120 === Bug fixes in 1.15 ===
119121 * (bug 16968) Special:Upload no longer throws useless warnings.

Follow-up revisions

RevisionCommit summaryAuthorDate
r48780Revert r47569 and subsequent related revisions. These still break logging in ...werdna02:27, 25 March 2009
r78536Rm unused javascript added in r47637 (follow up to r47569) and not reverted w...happy-melon16:04, 17 December 2010
r95597Remove a message for a feature introduced with r47569 and reverted with r48780.raymond11:01, 27 August 2011

Comments

#Comment by MZMcBride (talk | contribs)   19:49, 20 February 2009

This absolutely must have logging.

#Comment by Aaron Schulz (talk | contribs)   06:00, 12 March 2009

Logging added in r47637 (and r47641 and 47642)

#Comment by Aaron Schulz (talk | contribs)   05:57, 12 March 2009

Message syntax error fixed in r47570

#Comment by Aaron Schulz (talk | contribs)   05:58, 12 March 2009

Temporary password login form fixed in r47976

#Comment by Brion VIBBER (talk | contribs)   08:56, 25 March 2009

This has all gotten reverted due to general breakage of password-reset-by-mail.

Status & tagging log