Prado\Security\TSecurityManager::getValidationKey PHP Method

getValidationKey() public method

public getValidationKey ( ) : string
return string the private key used to generate HMAC. If the key is not explicitly set, a random one is generated and returned.
    public function getValidationKey()
    {
        if (null === $this->_validationKey) {
            if (null === ($this->_validationKey = $this->getApplication()->getGlobalState(self::STATE_VALIDATION_KEY))) {
                $this->_validationKey = $this->generateRandomKey();
                $this->getApplication()->setGlobalState(self::STATE_VALIDATION_KEY, $this->_validationKey, null, true);
            }
        }
        return $this->_validationKey;
    }

Usage Example

示例#1
0
 public function testValidationKey()
 {
     $sec = new TSecurityManager();
     $sec->init(null);
     // Random validation key
     $valkey = $sec->getValidationKey();
     self::assertEquals($valkey, self::$app->getGlobalState(TSecurityManager::STATE_VALIDATION_KEY));
     $sec->setValidationKey('aKey');
     self::assertEquals('aKey', $sec->getValidationKey());
     try {
         $sec->setValidationKey('');
         self::fail('Expected TInvalidDataValueException not thrown');
     } catch (TInvalidDataValueException $e) {
     }
 }