Merge "Fix creating non-parameterized hashes in ParameterizedPassword"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 30 Oct 2014 00:17:07 +0000 (00:17 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 30 Oct 2014 00:17:07 +0000 (00:17 +0000)
includes/password/MWOldPassword.php
includes/password/ParameterizedPassword.php
tests/phpunit/includes/TestUser.php

index 0ba407f..afa5cac 100644 (file)
@@ -38,7 +38,7 @@ class MWOldPassword extends ParameterizedPassword {
        public function crypt( $plaintext ) {
                global $wgPasswordSalt;
 
-               if ( $wgPasswordSalt && count( $this->args ) == 1 ) {
+               if ( $wgPasswordSalt && count( $this->args ) === 1 ) {
                        $this->hash = md5( $this->args[0] . '-' . md5( $plaintext ) );
                } else {
                        $this->args = array();
index 4d6e415..187f895 100644 (file)
@@ -83,10 +83,14 @@ abstract class ParameterizedPassword extends Password {
        }
 
        public function toString() {
-               return
-                       ':' . $this->config['type'] . ':' .
-                       implode( $this->getDelimiter(), array_merge( $this->params, $this->args ) ) .
-                       $this->getDelimiter() . $this->hash;
+               $str = ':' . $this->config['type'] . ':';
+
+               if ( count( $this->params ) || count( $this->args ) ) {
+                       $str .= implode( $this->getDelimiter(), array_merge( $this->params, $this->args ) );
+                       $str .= $this->getDelimiter();
+               }
+
+               return $str . $this->hash;
        }
 
        /**
index 39822dc..499353e 100644 (file)
@@ -114,8 +114,8 @@ class TestUser {
                $passwordFactory = $this->user->getPasswordFactory();
                $oldDefaultType = $passwordFactory->getDefaultType();
 
-                // B is salted MD5 (thus fast) ... we don't care about security here, this is test only
-               $passwordFactory->setDefaultType( 'B' ); // @TODO: Change this to A once that is fixed: https://gerrit.wikimedia.org/r/167523
+                // A is unsalted MD5 (thus fast) ... we don't care about security here, this is test only
+               $passwordFactory->setDefaultType( 'A' );
                $newPassword = $passwordFactory->newFromPlaintext( $password , $this->user->getPassword() );
 
                $change = false;