public function testCompareCredentials() { $credentials = new Credentials('Ma27', 'test-password'); $this->assertTrue($credentials->compare(new AuthDTO('Ma27', 'test-password'))); $this->assertFalse($credentials->compare(new AuthDTO('foo', 'test-password'))); $this->assertFalse($credentials->compare(new AuthDTO('Ma27', '123456'))); }
/** * Changes the user's password * * @param ChangePasswordDTO $passwordData * * @return boolean * * @throws ChangePasswordException If the old password is invalid * @throws ChangePasswordException If no token is present */ public function changePassword(ChangePasswordDTO $passwordData) { $this->ensureActivated(); if (null === $this->token) { throw ChangePasswordException::fromInsufficientToken(); } if (!$this->credentials->getPassword()->compare($passwordData->getOldPassword())) { throw ChangePasswordException::fromInvalidPassword(); } $credentialSnapshot = $this->credentials; $this->credentials = new Credentials($credentialSnapshot->getUsername(), $passwordData->getNewPassword()); return true; }