/** * Constructs dynamic node type * * @param string */ public function __construct($label) { $this->label = $label; if (empty($this->uuid)) { $this->uuid = $label . Algorithms::generateRandomString(6); } }
/** * Generates a new key & saves it encrypted with a hashing strategy * * @param string $name * @return string * @throws \TYPO3\Flow\Security\Exception */ public function generateKey($name) { if (strlen($name) === 0) { throw new \TYPO3\Flow\Security\Exception('Required name argument was empty', 1334215474); } $password = \TYPO3\Flow\Utility\Algorithms::generateRandomString($this->passwordGenerationLength); $this->persistKey($name, $password); return $password; }
/** * Constructs dynamic property * * @param string $label * @param DynamicNodeType $dynamicNodeType * @param string $placeholder * @param string $defaultValue */ public function __construct($label, $dynamicNodeType, $placeholder, $defaultValue) { $this->label = $label; $this->dynamicNodeType = $dynamicNodeType; $this->placeholder = $placeholder; $this->defaultValue = $defaultValue; if (empty($this->uuid)) { $this->uuid = $label . Algorithms::generateRandomString(6); } }
/** * Initialize */ protected function initialize() { $this->logPrefix = $this->logPrefix ?: Algorithms::generateRandomString(12); $contextConfiguration = ['workspaceName' => 'live', 'invisibleContentShown' => TRUE]; $context = $this->contextFactory->create($contextConfiguration); $this->rootNode = $context->getRootNode(); $siteNodePath = $this->options['siteNodePath']; $this->siteNode = $this->rootNode->getNode($siteNodePath); if ($this->siteNode === NULL) { throw new Exception(sprintf('Site node not found (%s)', $siteNodePath), 1425077201); } }
/** * Sends an email to a user with the new password * * @param \TYPO3\Flow\Security\Account $account * @param array $settings * @param string $newEnteredPassword * @return boolean $success */ public function sendMail(Account $account, $settings, $newEnteredPassword = NULL) { if ($newEnteredPassword !== NULL) { $newPassword = $newEnteredPassword; } else { $newPassword = $this->algorithms->generateRandomString(10); $account->setCredentialsSource($this->hashService->hashPassword($newPassword, 'default')); $this->accountRepository->update($account); } // @TODO: Localize the email format $mailBody[] = 'Dear %1$s'; $mailBody[] = ''; $mailBody[] = 'Your password for First Visit.'; $mailBody[] = 'The password is %2$s'; $mailBody[] = ''; $mailBody[] = 'If you haven\'t requested this information, please change your password at once'; $mailBody[] = 'as others might be able to access your account'; $success = FALSE; $message = new SwiftMessage(); if ($message->setTo(array($account->getAccountIdentifier() => $account->getParty()->getName()))->setFrom(array($settings['PasswordRecovery']['Sender']['Email'] => $settings['PasswordRecovery']['Sender']['Name']))->setSubject($settings['PasswordRecovery']['Subject'])->setBody(vsprintf(implode(PHP_EOL, $mailBody), array($account->getParty()->getName(), $newPassword)))->send()) { $success = TRUE; } return $success; }
/** */ protected function createAndPersistTestEntity() { $testEntity = new Tweet(); $testEntity->setDate(new \DateTime()); $testEntity->setMessage('This is a test message ' . \TYPO3\Flow\Utility\Algorithms::generateRandomString(8)); $testEntity->setUsername('Zak McKracken' . \TYPO3\Flow\Utility\Algorithms::generateRandomString(8)); $this->testEntityRepository->add($testEntity); $this->persistenceManager->persistAll(); $this->persistenceManager->clearState(); return $testEntity; }
/** * Generates and propagates a new session ID and transfers all existing data * to the new session. * * @return string The new session ID * @throws \TYPO3\Flow\Session\Exception\SessionNotStartedException * @throws \TYPO3\Flow\Session\Exception\OperationNotSupportedException * @api */ public function renewId() { if ($this->started !== true) { throw new \TYPO3\Flow\Session\Exception\SessionNotStartedException('Tried to renew the session identifier, but the session has not been started yet.', 1351182429); } if ($this->remote === true) { throw new \TYPO3\Flow\Session\Exception\OperationNotSupportedException(sprintf('Tried to renew the session identifier on a remote session (%s).', $this->sessionIdentifier), 1354034230); } $this->removeSessionMetaDataCacheEntry($this->sessionIdentifier); $this->sessionIdentifier = Algorithms::generateRandomString(32); $this->writeSessionMetaDataCacheEntry(); $this->sessionCookie->setValue($this->sessionIdentifier); return $this->sessionIdentifier; }
/** * Creates a BCrypt hash * * @param string $password The plaintext password to hash * @param string $staticSalt Optional static salt that will not be stored in the hashed password * @return string the result of the crypt() call */ public function hashPassword($password, $staticSalt = NULL) { $dynamicSalt = \TYPO3\Flow\Utility\Algorithms::generateRandomString(22, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./'); return crypt($password, '$2a$' . $this->cost . '$' . $dynamicSalt); }
/** * @param array $setting * @param string $logPrefix * @throws InvalidArgumentException */ public function __construct(array $setting, $logPrefix = NULL) { if (!isset($setting['__currentPresetName'])) { throw new InvalidArgumentException('Missing or invalid "__currentPresetName" in preset part settings', 1426156156); } $this->currentPresetName = $setting['__currentPresetName']; if (!isset($setting['__currentPartName'])) { throw new InvalidArgumentException('Missing or invalid "__currentPartName" in preset part settings', 1426156155); } $this->currentPartName = $setting['__currentPartName']; if (!isset($setting['label']) || !is_string($setting['label'])) { throw new InvalidArgumentException('Missing or invalid "Label" in preset part settings', 1426156157); } $this->label = (string) $setting['label']; if (!isset($setting['dataProviderClassName']) || !is_string($setting['dataProviderClassName'])) { throw new InvalidArgumentException('Missing or invalid "dataProviderClassName" in preset part settings', 1426156158); } $this->dataProviderClassName = (string) $setting['dataProviderClassName']; if (!isset($setting['importerClassName']) || !is_string($setting['importerClassName'])) { throw new InvalidArgumentException('Missing or invalid "dataProviderClassName" in preset part settings', 1426156159); } $this->importerClassName = (string) $setting['importerClassName']; $this->batchSize = isset($setting['batchSize']) ? (int) $setting['batchSize'] : NULL; $this->offset = isset($setting['batchSize']) ? 0 : NULL; $this->dataProviderOptions = isset($setting['dataProviderOptions']) ? $setting['dataProviderOptions'] : []; $this->currentBatch = 1; $this->logPrefix = $logPrefix ?: Algorithms::generateRandomString(12); }
/** * Batch process of the given preset * * @param string $preset * @param string $parts */ public function batchCommand($preset, $parts = NULL) { $this->startTime = microtime(TRUE); $parts = Arrays::trimExplode(',', $parts); $this->outputLine('Start import ...'); $logPrefix = Algorithms::generateRandomString(12); $presetSettings = Arrays::getValueByPath($this->settings, array('presets', $preset)); if (!is_array($presetSettings)) { $this->outputLine(sprintf('Preset "%s" not found ...', $preset)); $this->quit(1); } array_walk($presetSettings, function ($partSetting, $partName) use($preset, $logPrefix, $parts) { $this->elapsedTime = 0; $this->batchCounter = 0; $this->outputLine(); $this->outputFormatted(sprintf('<b>%s</b>', $partSetting['label'])); $partSetting['__currentPresetName'] = $preset; $partSetting['__currentPartName'] = $partName; $partSetting = new PresetPartDefinition($partSetting, $logPrefix); if ($parts !== array() && !in_array($partName, $parts)) { $this->outputLine('Skipped'); return; } if ($partSetting->getBatchSize()) { while (($count = $this->executeCommand($partSetting)) > 0) { $partSetting->nextBatch(); } } else { $this->executeCommand($partSetting); } }); $this->outputLine(); $this->outputLine('Import finished'); }
/** * @test * @dataProvider randomStringCharactersDataProvider */ public function generateRandomStringGeneratesOnlyDefinedCharactersRange($regularExpression, $charactersClass) { $this->assertRegExp($regularExpression, Algorithms::generateRandomString(64, $charactersClass)); }
/** * Hash a password for storage using PBKDF2 and the configured parameters. * Will use a combination of a random dynamic salt and the given static salt. * * @param string $password Cleartext password that should be hashed * @param string $staticSalt Static salt that will be appended to the random dynamic salt * @return string A Base64 encoded string with the derived key (hashed password) and dynamic salt */ public function hashPassword($password, $staticSalt = null) { $dynamicSalt = UtilityAlgorithms::generateRandomString($this->dynamicSaltLength); $result = Algorithms::pbkdf2($password, $dynamicSalt . $staticSalt, $this->iterationCount, $this->derivedKeyLength, $this->algorithm); return base64_encode($dynamicSalt) . ',' . base64_encode($result); }
/** * @return \TYPO3\Flow\Security\Account * @throws Exception * @throws \TYPO3\Flow\Persistence\Exception\IllegalObjectTypeException */ protected function generateTokenAccount() { $account = $this->securityContext->getAccount(); $tokenAccount = $this->accountFactory->createAccountWithPassword($account->getAccountIdentifier(), Algorithms::generateRandomString(25), array_keys($account->getRoles()), $this->apiToken->getAuthenticationProviderName()); $this->accountRepository->add($tokenAccount); $this->persistenceManager->persistAll(); return $tokenAccount; }
/** * Generate a new password reset token * * @throws Exception If the user doesn't have an account yet */ protected function generateResetPasswordToken() { $this->resetPasswordToken = Algorithms::generateRandomString(30); $this->resetPasswordTokenValidUntil = (new \DateTime())->add(\DateInterval::createFromDateString($this->resetPasswordTokenTimeout)); }
/** * Generate a new activation token * * @throws Exception If the user has an account already */ public function generateActivationToken() { $this->activationToken = Algorithms::generateRandomString(30); $this->activationTokenValidUntil = (new \DateTime())->add(\DateInterval::createFromDateString($this->activationTokenTimeout)); }