public function testHashPassword()
 {
     $credentials = new Credentials('Ma27', 'test-password');
     $this->assertSame('Ma27', $credentials->getUsername());
     $this->assertInstanceOf(Password::class, $password = $credentials->getPassword());
     $this->assertTrue($password->isHashed());
 }
 /**
  * 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;
 }