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

keyExists() public method

Checks if a key exists
public keyExists ( string $name ) : boolean
$name string
return boolean
    public function keyExists($name)
    {
        if (strlen($name) === 0) {
            throw new SecurityException('Required name argument was empty', 1334215344);
        }
        if (!file_exists($this->getKeyPathAndFilename($name))) {
            return false;
        }
        return true;
    }

Usage Example

Ejemplo 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);
 }