$this->setToken();
$passwordFactory = self::getPasswordFactory();
- if ( $str === null ) {
- $this->mPassword = $passwordFactory->newFromCiphertext( null );
- } else {
- $this->mPassword = $passwordFactory->newFromPlaintext( $str );
- }
+ $this->mPassword = $passwordFactory->newFromPlaintext( $str );
$this->mNewpassword = $passwordFactory->newFromCiphertext( null );
$this->mNewpassTime = null;
public function setNewpassword( $str, $throttle = true ) {
$this->loadPasswords();
+ $this->mNewpassword = self::getPasswordFactory()->newFromPlaintext( $str );
if ( $str === null ) {
- $this->mNewpassword = '';
$this->mNewpassTime = null;
- } else {
- $this->mNewpassword = self::getPasswordFactory()->newFromPlaintext( $str );
- if ( $throttle ) {
- $this->mNewpassTime = wfTimestampNow();
- }
+ } elseif ( $throttle ) {
+ $this->mNewpassTime = wfTimestampNow();
}
}
* If no existing object is given, make a new default object. If one is given, clone that
* object. Then pass the plaintext to Password::crypt().
*
- * @param string $password Plaintext password
+ * @param string|null $password Plaintext password, or null for an invalid password
* @param Password|null $existing Optional existing hash to get options from
* @return Password
*/
public function newFromPlaintext( $password, Password $existing = null ) {
+ if ( $password === null ) {
+ return new InvalidPassword( $this, array( 'type' => '' ), null );
+ }
+
if ( $existing === null ) {
$config = $this->types[$this->default];
$obj = new $config['class']( $this, $config );
$this->assertFalse( $invalid1->equals( $invalid2 ) );
}
+
+ public function testInvalidPlaintext() {
+ $invalid = User::getPasswordFactory()->newFromPlaintext( null );
+
+ $this->assertInstanceOf( 'InvalidPassword', $invalid );
+ }
}