Legoktm has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/167859

Change subject: Move password update logic out of CentralAuthUser::matchHash()
......................................................................

Move password update logic out of CentralAuthUser::matchHash()

Bug: 71323
Change-Id: I12b7bc650798462f6b8549e5d3c3319dfc16b6ce
---
M includes/CentralAuthUser.php
1 file changed, 14 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralAuth 
refs/changes/59/167859/1

diff --git a/includes/CentralAuthUser.php b/includes/CentralAuthUser.php
index 15fa7a9..4f13876 100644
--- a/includes/CentralAuthUser.php
+++ b/includes/CentralAuthUser.php
@@ -996,7 +996,7 @@
                // Look for accounts we can match by password
                foreach ( $rows as $row ) {
                        $wiki = $row['wiki'];
-                       if ( $this->matchHash( $password, $row['id'], 
$row['password'] ) ) {
+                       if ( $this->matchHash( $password, $row['id'], 
$row['password'] )->isGood() ) {
                                wfDebugLog( 'CentralAuth',
                                        "Attaching '$this->mName' on $wiki by 
password" );
                                $this->attach( $wiki, 'password' );
@@ -1580,9 +1580,14 @@
                }
 
                list( $salt, $crypt ) = $this->getPasswordHash();
-               if ( $this->matchHash( $password, $salt, $crypt, /* $update = 
*/ true ) ) {
+               $status = $this->matchHash( $password, $salt, $crypt );
+               if ( $status->isGood() ) {
                        wfDebugLog( 'CentralAuth',
                                "authentication for '$this->mName' succeeded" );
+                       if ( User::getPasswordFactory()->needsUpdate( 
$status->getValue() ) ) {
+                               $this->setPassword( $password );
+                               $this->saveSettings();
+                       }
                        return "ok";
                } else {
                        wfDebugLog( 'CentralAuth',
@@ -1612,10 +1617,9 @@
         * @param $plaintext  String User-provided password plaintext.
         * @param $salt       String The hash "salt", eg a local id for 
migrated passwords.
         * @param $encrypted  String Fully salted and hashed database crypto 
text from db.
-        * @param $update     Boolean Whether to update the password if 
necessary
-        * @return Bool true on match.
+        * @return Status
         */
-       protected function matchHash( $plaintext, $salt, $encrypted, $update = 
false ) {
+       protected function matchHash( $plaintext, $salt, $encrypted ) {
                global $wgPasswordSalt;
                $matched = false;
                $passwordFactory = User::getPasswordFactory();
@@ -1640,12 +1644,11 @@
                        }
                }
 
-               if ( $update && $matched && $passwordFactory->needsUpdate( 
$hash ) ) {
-                       $this->setPassword( $plaintext, false );
-                       $this->saveSettings();
+               if ( $matched ) {
+                       return Status::newGood( $hash );
+               } else {
+                       return Status::newFatal( 'bad' );
                }
-
-               return $matched;
        }
 
        /**
@@ -1656,7 +1659,7 @@
         */
        protected function matchHashes( $passwords, $salt, $encrypted ) {
                foreach ( $passwords as $plaintext ) {
-                       if ( $this->matchHash( $plaintext, $salt, $encrypted ) 
) {
+                       if ( $this->matchHash( $plaintext, $salt, $encrypted 
)->isGood() ) {
                                return true;
                        }
                }

-- 
To view, visit https://gerrit.wikimedia.org/r/167859
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I12b7bc650798462f6b8549e5d3c3319dfc16b6ce
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralAuth
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to