Neos\Flow\Security\Cryptography\FileBasedSimpleKeyService::generateKey PHP Method

generateKey() public method

Generates a new key & saves it encrypted with a hashing strategy
public generateKey ( string $name ) : string
$name string
return string
    public function generateKey($name)
    {
        if (strlen($name) === 0) {
            throw new SecurityException('Required name argument was empty', 1334215474);
        }
        $password = UtilityAlgorithms::generateRandomString($this->passwordGenerationLength);
        $this->persistKey($name, $password);
        return $password;
    }

Usage Example

Esempio n. 1
0
 /**
  * @param integer $step The requested setup step
  * @return void
  */
 public function loginAction($step = 0)
 {
     if ($this->fileBasedSimpleKeyService->keyExists($this->keyName) === false || file_exists($this->settings['initialPasswordFile'])) {
         $setupPassword = $this->fileBasedSimpleKeyService->generateKey($this->keyName);
         $initialPasswordFileContents = 'The setup password is:' . PHP_EOL;
         $initialPasswordFileContents .= PHP_EOL;
         $initialPasswordFileContents .= $setupPassword . PHP_EOL;
         $initialPasswordFileContents .= PHP_EOL;
         $initialPasswordFileContents .= 'After you successfully logged in, this file is automatically deleted for security reasons.' . PHP_EOL;
         $initialPasswordFileContents .= 'Make sure to save the setup password for later use.' . PHP_EOL;
         $result = file_put_contents($this->settings['initialPasswordFile'], $initialPasswordFileContents);
         if ($result === false) {
             $this->addFlashMessage('It was not possible to save the initial setup password to file "%s". Check file permissions and retry.', 'Password Generation Failure', Message::SEVERITY_ERROR, [$this->settings['initialPasswordFile']]);
         } else {
             $this->view->assign('initialPasswordFile', $this->settings['initialPasswordFile']);
         }
     }
     $this->view->assign('step', $step);
 }