Verify a session nonce

Checks to see if the nonce has been generated before.  If so, validate it's syntax and remove it.

@param string $nonce The nonce to verify
@return  bool Returns true if the nonce exists and is valid.
333141
public function verifyNonce($nonce)
    {
        if(isset($this->nonces[$nonce]))
        {
            //Remove the nonce from the store
            unset($this->nonces[$nonce]);

            //Validate the nonce
            $secret = $this->getSecret();
            if($this->_validateNonce($secret, $nonce)) {
                return true;
            }
        }

        return false;
    }
767734
protected function validateSessionObject($session) {
    // make sure some essential fields exist
    if (is_array($session) &&
        isset($session['uid']) &&
        isset($session['access_token']) &&
        isset($session['sig'])) {
      // validate the signature
      $session_without_sig = $session;
      unset($session_without_sig['sig']);
      $expected_sig = self::generateSignature(
        $session_without_sig,
        $this->getApiSecret()
      );
      if ($session['sig'] != $expected_sig) {
        self::errorLog('Got invalid session signature in cookie.');
        $session = null;
      }
      // check expiry time
    } else {
      $session = null;
    }
    return $session;
  }
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);
    }
927461
protected function nonce()
    {
        $action = ($this->getParameter('action') == null) ?
                    $this->RequestContext->getControls()->getControl('action')
                  : $this->getParameter('action');

        return $this->Nonces->create($action);
    }
601242
protected function getNonceValue()
    {
        if (null === $this->nonce) {
            $this->nonce = new Nonce();
        }
        return $this->nonce->generate();
    }
509752
private function isSessionValid($session)
    {
        $sessions = $this->getMeta()->sessions;
        $sessionTtl = $this->getSessionTtl();

        foreach ($sessions as $s) {
            if ($s['sid'] == $session && ($s['created'] + $sessionTtl) > time()) {
                return true;
            }
        }

        return false;
    }
438531
protected function getNonceSalt()
    {
        // Allow users to set their own nonce
        if (!is_null($this->getConfig('nonce'))) {
            return $this->request->generateNonceKey($this->getConfig('nonce'));
        // Use the entity if it is present
        } elseif (!is_null($this->associatedEntity)) {
            return $this->request->generateNonceKey($this->associatedEntity);
        }

        // Fallback to something custom for the Helper
        return $this->request->generateNonceKey();
    }
1159879
public function setNonce($nonce = null)
    {
        $this->nonce = $nonce;
        if ($nonce === null) {
            $this->nonce = new Nonce();
        }
        return $this;
    }
546195
public function check($code, $namespace, $recipient)
    {
        $cacheKey = $this->getCacheKey($namespace, $recipient);
        /** @var ValidCode $validCode */
        $validCode = $this->cache->get($cacheKey);
        if (empty($validCode) || $validCode->isExpired() || $validCode->getCode() != $code) {
            return false;
        }
        //验证成功后删除缓存中保存的验证码
        $this->cache->delete($cacheKey);
        return true;
    }
1047238
private static function validateNotBefore(Parse $parse): bool
    {
        try {
            $parse->validateNotBefore();
        } catch (ValidateException $e) {
            if ($e->getCode() === 5) {
                return false;
            }
        }

        return true;
    }
859490
function verifyNonce( $timestamp, $md5 ) {

		// Within range of 5 minutes?
		$within_range = time() - $timestamp;
		if ( $within_range > ( MINUTE_IN_SECONDS * 5 ) ) {
			return false;
		}

		// Correct md5?
		if ( md5( NONCE_KEY . $timestamp ) !== $md5 ) {
			return false;
		}

		return true;
	}
41147
public function saveConsumerNonce($nonce)
    {

        $id = $nonce->getConsumer()->getRecordId();
        $value = $nonce->getValue();
        $expires = date("{$this->dateFormat} {$this->timeFormat}", $nonce->expires);
        $sql = "INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::NONCE_TABLE_NAME . ' (consumer_pk, value, expires) VALUES (:id, :value, :expires)';
        $query = $this->db->prepare($sql);
        $query->bindValue('id', $id, PDO::PARAM_INT);
        $query->bindValue('value', $value, PDO::PARAM_STR);
        $query->bindValue('expires', $expires, PDO::PARAM_STR);
        $ok = $query->execute();

        return $ok;

    }
194418
public function exists($key)
    {
        // Checks if we need to verify a nested array
        if (preg_match('/\.+/', $key))
        {
            $keys   = explode('.', $key);
            $levels = count($keys);

            // Quick workaround
            if ($levels == 4)
            {
                return isset($this->params[$keys[0]][$keys[1]][$keys[2]][$keys3]);
            }
            else if ($levels == 3)
            {
                return isset($this->params[$keys[0]][$keys[1]][$keys[2]]);
            }
            else
            {
                return isset($this->params[$keys[0]][$keys[1]]);
            }
        }

        // Non-nested array validation
        if (array_key_exists($key, $this->params))
        {
            return true;
        }

        return false;
    }
1091182
public static function isValidNie(string $nie): bool
    {
        if (!preg_match(self::NIE_REGEX, $nie, $matches)) {
            return false;
        }

        $nieType = strpos(self::NIE_TYPES, $matches['type']);
        $nie = $nieType . $matches['number'];

        return self::DNINIE_CHECK_TABLE[$nie % 23] === $matches['check'];
    }
24435
public function saveConsumerNonce($nonce)
    {

        $expires = date("{$this->dateFormat} {$this->timeFormat}", $nonce->expires);
        $sql = sprintf("INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::NONCE_TABLE_NAME . " (consumer_pk, value, expires) VALUES (%d, %s, %s)",
                       $nonce->getConsumer()->getRecordId(), DataConnector::quoted($nonce->getValue()),
                       DataConnector::quoted($expires));
        $ok = mysql_query($sql);

        return $ok;

    }
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
			]);
		}
	}
4784
public function validate($entity)
    {
        //reset the error message
        $context = $this->getCommandContext();
        $context->entity = $entity;
        if ($entity->isValidatable()) {
            $entity->resetErrors();
        }
        $result = $this->getCommandChain()->run('on.validate', $context);

        return $result !== false;
    }