/** * @param string $password * @return bool */ private function setPassword($password) { $passwordFactory = $this->user->getPasswordFactory(); $oldDefaultType = $passwordFactory->getDefaultType(); // 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; if (!$this->user->getPassword()->equals($newPassword)) { // Password changed $this->user->setPassword($password); $change = true; } $passwordFactory->setDefaultType($oldDefaultType); return $change; }
/** * @param string $username the username * @param string $password password for the account * @param array $attrs associative array of global user attributs * @param array $wikis array of arrays of wiki, attachement method */ public function __construct($username, $password, array $attrs = array(), array $wikis = array(), $createLocal = true) { $this->username = $username; $this->password = $password; $attrs += array('gu_id' => '1000', 'gu_password' => User::getPasswordFactory()->newFromPlaintext($password)->toString(), 'gu_salt' => '', 'gu_auth_token' => '1234', 'gu_locked' => 0, 'gu_hidden' => CentralAuthUser::HIDDEN_NONE, 'gu_registration' => '20130627183537', 'gu_email' => 'test@localhost', 'gu_email_authenticated' => '20130801040214', 'gu_home_db' => wfWikiID(), 'gu_enabled' => '', 'gu_enabled_method' => null); $this->guId = $attrs['gu_id']; $this->passHash = $attrs['gu_password']; $this->salt = $attrs['gu_salt']; $this->authToken = $attrs['gu_auth_token']; $this->locked = $attrs['gu_locked']; $this->hidden = $attrs['gu_hidden']; $this->registration = $attrs['gu_registration']; $this->email = $attrs['gu_email']; $this->emailAuthenticated = $attrs['gu_email_authenticated']; $this->homeDb = $attrs['gu_home_db']; $this->enabled = $attrs['gu_enabled']; $this->enabledMethod = $attrs['gu_enabled_method']; $this->wikis = array(); foreach ($wikis as $wiki) { $this->wikis[] = array('lu_wiki' => $wiki[0], 'lu_name' => $this->username, 'lu_attached_timestamp' => $this->registration, 'lu_attached_method' => $wiki[1]); } $this->createLocal = $createLocal; }
public function testInvalidPlaintext() { $invalid = User::getPasswordFactory()->newFromPlaintext(null); $this->assertInstanceOf('InvalidPassword', $invalid); }
/** * Salt and hash a new plaintext password. * @param string $password plaintext * @return array of strings, salt and hash */ protected function saltedPassword($password) { return array('', User::getPasswordFactory()->newFromPlaintext($password)->toString()); }
/** * @covers InvalidPassword::equals */ public function testInvalidUnequalInvalid() { $invalid1 = User::getPasswordFactory()->newFromCiphertext(null); $invalid2 = User::getPasswordFactory()->newFromCiphertext(null); $this->assertFalse($invalid1->equals($invalid2)); }