Generate a nonce value that is validated in future requests.

@return string
338584
protected function generateNonce()
    {
        $expiryTime = microtime(true) + $this->getConfig('nonceLifetime');
        $secret = $this->getConfig('secret');
        $signatureValue = hash_hmac('sha1', $expiryTime . ':' . $secret, $secret);
        $nonceValue = $expiryTime . ':' . $signatureValue;

        return base64_encode($nonceValue);
    }
378847
protected function generatePayload($nonce, $iat, $exp)
    {
        $payload = new \stdClass();
        $payload->nonce = $nonce;
        $payload->iat = $iat;
        $payload->ttl = $exp - $iat;
        $payload->exp = $exp;

        return $payload;
    }
1018565
private function _getCnonce()
    {
        // TODO: I reused the nonce function from the DigestMD5 class.
        // I should probably make this a protected function in Common.
        if (@file_exists('/dev/urandom') && $fd = @fopen('/dev/urandom', 'r')) {
            return base64_encode(fread($fd, 32));

        } elseif (@file_exists('/dev/random') && $fd = @fopen('/dev/random', 'r')) {
            return base64_encode(fread($fd, 32));

        } else {
            $str = '';
            for ($i=0; $i<32; $i++) {
                $str .= chr(mt_rand(0, 255));
            }

            return base64_encode($str);
        }
    }
384192
def generate_nonce():
        
        nonce = ''.join([str(randint(0, 9)) for i in range(8)])
        return HMAC(
            nonce.encode(),
            "secret".encode(),
            sha1
        ).hexdigest()
1201481
public function valid()
    {
        $encryptStr = "";
        if ($_SERVER['REQUEST_METHOD'] == "POST") {
            $postStr = file_get_contents("php://input");
            $disableEntities = libxml_disable_entity_loader(true);
            $array = (array)simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
            libxml_disable_entity_loader($disableEntities);
            $this->encrypt_type = isset($_GET["encrypt_type"]) ? $_GET["encrypt_type"] : '';
            if ($this->encrypt_type == 'aes') {
                $encryptStr = $array['Encrypt'];
                !class_exists('Prpcrypt', false) && require __DIR__ . '/Prpcrypt.php';
                $pc = new Prpcrypt($this->encodingAesKey);
                $array = $pc->decrypt($encryptStr, $this->appid);
                if (!isset($array[0]) || intval($array[0]) > 0) {
                    $this->errCode = $array[0];
                    $this->errMsg = $array[1];
                    Tools::log("Interface Authentication Failed. {$this->errMsg}[{$this->errCode}]", "ERR - {$this->appid}");
                    return false;
                }
                $this->postxml = $array[1];
                empty($this->appid) && $this->appid = $array[2];
            } else {
                $this->postxml = $postStr;
            }
        } elseif (isset($_GET["echostr"])) {
            if ($this->checkSignature()) {
                @ob_clean();
                exit($_GET["echostr"]);
            }
            return false;
        }
        if (!$this->checkSignature($encryptStr)) {
            $this->errMsg = 'Interface authentication failed, please use the correct method to call.';
            return false;
        }
        return true;
    }
320400
public function nonceValidates($mixedNonceSalt)
    {
        $token = null;

        if ($this->hasPost("authenticity_token")) {
            $token = $this->post("authenticity_token");
        } elseif ($this->hasGet("authenticity_token")) {
            $token = $this->get("authenticity_token");
        }

        if (is_null($token)) {
            return false;
        }

        $key = $this->generateNonceKey($mixedNonceSalt);

        return wp_verify_nonce($token, $key);
    }
561255
public function generateNonceKey($mixedNonceSalt = null)
    {
        if (!is_string($mixedNonceSalt)) {
            if (is_object($mixedNonceSalt)) {
                $methods = get_class_methods($mixedNonceSalt);
                $mixedNonceSalt = get_class($mixedNonceSalt) . implode("", $methods);
            } elseif (is_array($mixedNonceSalt)) {
                $mixedNonceSalt = json_encode($mixedNonceSalt);
            }
        }

        $strataSalt = Strata::app()->hasConfig('security.salt') ?
            Strata::app()->getConfig('security.salt') :
            crc32(getenv('SERVER_ADDR'));

        return $strataSalt . md5($mixedNonceSalt);
    }
717388
def generate_nonce(length=8):
    """"""
    return ''.join([str(random.SystemRandom().randint(0, 9)) for i in range(length)])
1270555
public function generateVerifyCode(): string
    {
        if ($this->minLength > $this->maxLength) {
            $this->maxLength = $this->minLength;
        }
        if ($this->minLength < 3) {
            $this->minLength = 3;
        }
        if ($this->maxLength > 20) {
            $this->maxLength = 20;
        }
        $length = random_int($this->minLength, $this->maxLength);

        $letters = 'bcdfghjklmnpqrstvwxyz';
        $vowels = 'aeiou';
        $code = '';
        for ($i = 0; $i < $length; ++$i) {
            if (($i % 2 && random_int(0, 10) > 2) || (!($i % 2) && random_int(0, 10) > 9)) {
                $code .= $vowels[random_int(0, 4)];
            } else {
                $code .= $letters[random_int(0, 20)];
            }
        }

        return $code;
    }
369504
protected function _getCnonce()
    {
        if ((@is_readable('/dev/urandom') &&
             ($fd = @fopen('/dev/urandom', 'r'))) ||
            (@is_readable('/dev/random') &&
             ($fd = @fopen('/dev/random', 'r')))) {
            $str = fread($fd, 32);
            fclose($fd);
        } else {
            $str = '';
            for ($i = 0; $i < 32; ++$i) {
                $str .= chr(mt_rand(0, 255));
            }
        }

        return base64_encode($str);
    }
303026
public function validate($nonce = null, $value = null, $message = null, $data = null)
	{

		$nonce = ($nonce) ? $nonce : $this->app['request']->get('nonce');
		$value = ($value) ? $value : $this->app['config']->get('app.key');

		if (!wp_verify_nonce($nonce, $value))
		{
			$default = ($msg = trans('ajax.invalid')) ? $msg : 'AJAX is invalid.';

			$data = ($data) ? $data : $this->app['request']->except(['nonce', 'action']);

			wp_send_json([
				'error' => true,
				'msg'   => ($message) ? $message : $default,
				'data'  => $data
			]);
		}
	}
735733
public function validate(): PathValidationResult
    {
        $n = count($this->_certificates);
        $state = ValidatorState::initialize($this->_config, $this->_trustAnchor,
            $n);
        for ($i = 0; $i < $n; ++$i) {
            $state = $state->withIndex($i + 1);
            $cert = $this->_certificates[$i];
            // process certificate (section 6.1.3.)
            $state = $this->_processCertificate($state, $cert);
            if (!$state->isFinal()) {
                // prepare next certificate (section 6.1.4.)
                $state = $this->_prepareNext($state, $cert);
            }
        }
        if (!isset($cert)) {
            throw new \LogicException("No certificates.");
        }
        // wrap-up (section 6.1.5.)
        $state = $this->_wrapUp($state, $cert);
        // return outputs
        return $state->getResult($this->_certificates);
    }
558274
protected function readNonceValue($nonce)
    {
        $value = null;

        if (null === $this->registryRepository) {
            if (true === is_readable($this->nonceDir.DIRECTORY_SEPARATOR.$nonce)) {
                $value = file_get_contents($this->nonceDir.DIRECTORY_SEPARATOR.$nonce);
            }
        } else {
            $value = $this->getRegistry($nonce)->getValue();
        }

        if (null !== $value) {
            $value = explode(';', $value);
        }

        return $value;
    }
82444
public function saveConsumerNonce($nonce) {
        global $DB;

        $data = [
            'consumerid' => $nonce->getConsumer()->getRecordId(),
            'value' => $nonce->getValue(),
            'expires' => $nonce->expires
        ];

        return $DB->insert_record($this->noncetable, (object) $data, false);
    }
1328247
public function generate()
    {
        $usable      = true;
        $this->bytes = openssl_random_pseudo_bytes($this->length, $usable);
        if ($usable === false) {
            // echo "Nonce is weak\n";
        }

        $this->nonce = base64_encode($this->bytes);

        return $this;
    }
889144
public static function verifyNonce($name, $value)
    {
        return isset($_POST[$name]) && wp_verify_nonce($_POST[$name], $value);
    }
285651
public static function getToken()
    {
        $token = self::getSessionToken();
        if (is_null($token)) {
            $nonce = self::generateNonce();
            self::setSessionToken($nonce);

        // Handle old tokens (< 2.6.0)
        } elseif (is_array($token)) {
            $nonce = key($token);
            self::setSessionToken($nonce);

        // New style tokens
        } else {
            $nonce = $token;
        }

        return $nonce;
    }