Verify that a policy is valid

@param array     $policy                 policy to verify
@param string?   $secret                 security secret

@return bool
353948
public function verify($policy, $secret)
    {
        try {
            $result = $this->generate($secret, $policy);
        } catch (FilestackException $e) {
            return false;
        }

        return $result;
    }
462773
public function isValid($username, $password, array $role = array())
    {
        foreach ($this->data as $user => $pass) {
            if ($user == $username && $pass == $password) {
                return true;
            }
        }

        return false;
    }
619131
public static function decrypt_secret($secret)
    {
        global $CFG;
        if ( $secret === null || $secret === false ) return $secret;
        if ( ! startsWith($secret,'AES::') ) return $secret;
        $secret = substr($secret, 5);
        $decr = AesCtr::decrypt($secret, $CFG->cookiesecret, 256) ;
        return $decr;
    }
634644
public function verifySignature($uri, $secret, $paramName)
    {
        $getParams = array();
        parse_str(parse_url($uri, PHP_URL_QUERY), $getParams);

        if (!isset($getParams[$paramName])) {
            return false;
        }

        // Explode hash and data from eachother
        $parts = explode('.', $getParams[$paramName]);

        $data = array_pop($parts);

        // Decode the data
        $data = json_decode($this->base64UriDecode($data));

        // Create a new signature based on the secret and data and compare it to the data
        // we're verifying, if it is correct, return the signed data.
        if ($this->createSignature($secret, $data) === $getParams[$paramName]) {
            return $data;
        }

        return false;
    }
335572
public function validate($secret = null, $algo = null)
    {
        $token = $this->token();
        $secret = $secret ?: $this->secret();
        $algo = $algo ?: $this->algorithm();

        return $this->jwt->validateToken($token, $secret, $algo);
    }
716105
public function verify($response)
    {
        if (!$this->secretKey) {
            throw new Exception('Missing secret key');
        }

        $params = array(
            'secret' => $this->secretKey,
            'response' => $response,
        );

        if ($this->ip !== null) {
            $params['remoteip'] = $this->ip;
        }

        $this->httpClient->setUri(self::VERIFY_SERVER);
        $this->httpClient->setParameterPost($params);

        if ($this->options) {
            $this->httpClient->setOptions($this->options);
        }

        $this->httpClient->setMethod('POST');
        $response = $this->httpClient->send();

        return new CaptchaResponse($response);
    }
1059949
protected function authenticate($key, $secret) {
		$token = $this->cache->get('Twitter_Application_Bearer_Token');
		if ($token === FALSE) {
			$bearerTokenCredentials = base64_encode(urlencode($key) . ':' . urlencode($secret));

			$uri = new Uri('https://api.twitter.com/oauth2/token');
			$httpRequest = Request::create($uri, 'POST');
			$httpRequest->setContent(http_build_query(array('grant_type' => 'client_credentials')));
			$httpRequest->setHeader('Authorization', 'Basic ' . $bearerTokenCredentials);
			$httpRequest->setHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8');

			$response = $this->requestEngine->sendRequest($httpRequest);
			$authenticationReponseBody = json_decode($response->getContent(), TRUE);
			if (!isset($authenticationReponseBody['token_type']) || $authenticationReponseBody['token_type'] !== 'bearer' || !isset($authenticationReponseBody['access_token'])) {
				throw new \Exception('Invalid authentication answer! Your application could not authenticate with Twitter.', 1424698337);
			}

			$token = $authenticationReponseBody['access_token'];
			$this->cache->set('Twitter_Application_Bearer_Token', $token);
		}

		return $token;
	}
902386
public function calculateIntersection(ValidatorState $state, array $policies): ValidatorState
    {
        $tree = clone $this;
        $valid_policy_node_set = $tree->_validPolicyNodeSet();
        // 2. If the valid_policy of any node in the valid_policy_node_set
        // is not in the user-initial-policy-set and is not anyPolicy,
        // delete this node and all its children.
        $valid_policy_node_set = array_filter($valid_policy_node_set,
            function (PolicyNode $node) use ($policies) {
                if ($node->isAnyPolicy()) {
                    return true;
                }
                if (in_array($node->validPolicy(), $policies)) {
                    return true;
                }
                $node->remove();
                return false;
            });
        // array of valid policy OIDs
        $valid_policy_set = array_map(
            function (PolicyNode $node) {
                return $node->validPolicy();
            }, $valid_policy_node_set);
        // 3. If the valid_policy_tree includes a node of depth n with
        // the valid_policy anyPolicy and the user-initial-policy-set 
        // is not any-policy
        foreach ($tree->_nodesAtDepth($state->index()) as $node) {
            if ($node->hasParent() && $node->isAnyPolicy()) {
                // a. Set P-Q to the qualifier_set in the node of depth n
                // with valid_policy anyPolicy.
                $pq = $node->qualifiers();
                // b. For each P-OID in the user-initial-policy-set that is not
                // the valid_policy of a node in the valid_policy_node_set,
                // create a child node whose parent is the node of depth n-1
                // with the valid_policy anyPolicy.
                $poids = array_diff($policies, $valid_policy_set);
                foreach ($tree->_nodesAtDepth($state->index() - 1) as $parent) {
                    if ($parent->isAnyPolicy()) {
                        // Set the values in the child node as follows: 
                        // set the valid_policy to P-OID, set the qualifier_set
                        // to P-Q, and set the expected_policy_set to {P-OID}.
                        foreach ($poids as $poid) {
                            $parent->addChild(
                                new PolicyNode($poid, $pq, array($poid)));
                        }
                        break;
                    }
                }
                // c. Delete the node of depth n with the
                // valid_policy anyPolicy.
                $node->remove();
            }
        }
        // 4. If there is a node in the valid_policy_tree of depth n-1 or less
        // without any child nodes, delete that node. Repeat this step until
        // there are no nodes of depth n-1 or less without children.
        if (!$tree->_pruneTree($state->index() - 1)) {
            return $state->withoutValidPolicyTree();
        }
        return $state->withValidPolicyTree($tree);
    }
197519
public function validateToken($token, $secret, $algorithm = 'HS256')
    {
        try {
            JWT::decode($token, $secret, [$algorithm]);
        } catch(\Exception $e) {
            return false;
        }

        return true;
    }
380498
public static function encrypt_secret($secret)
    {
        global $CFG;
        if ( startsWith($secret,'AES::') ) return $secret;
        $encr = AesCtr::encrypt($secret, $CFG->cookiesecret, 256) ;
        return 'AES::'.$encr;
    }
1100299
public static function validate($payload, $secret, $signature)
    {
        return hash_equals(self::compute($payload, $secret), $signature);
    }
233357
public static function validate(string $token, string $secret): bool
    {
        $parse = self::parser($token, $secret);

        if (!self::validateWithExpiration($parse)) {
            return false;
        }

        if (!self::validateNotBefore($parse)) {
            return false;
        }

        return true;
    }
1271575
public function validate( array $credentials = [] )
	{
		$credentials = [$this->storageKey => $credentials[$this->inputKey]];

		if ( $this->auth->retrieveByCredentials( $credentials ) )
			return true;

		return false;
	}
439266
public function verify(string $signature, string $data, string $secret): bool
    {
        $compareSignature = $this->sign($data, $secret);

        return $compareSignature === $signature;
    }
264581
protected function hasCredentials(array $credentials, $guard = null)
    {
        $provider = $this->app->make('auth')->guard($guard)->getProvider();

        $user = $provider->retrieveByCredentials($credentials);

        return $user && $provider->validateCredentials($user, $credentials);
    }
25429
private function getPoliciesNumbers(array $policies): array
    {
        $policiesNumbers = array_column($policies, 'id');

        return array_combine($policiesNumbers, array_fill_keys($policiesNumbers, false));
    }
573534
protected function validate($jsonData, $secret) {
		$signatureHeader = $this->readSignatureHeader();
		list ($algorithm, $hash) = explode('=', $signatureHeader);
		$calculatedHash = hash_hmac($algorithm, $jsonData, $secret);
		if ($calculatedHash !== $hash) {
			throw new \RuntimeException('Invalid request hash - please make sure you entered the correct "secret"', 1411225210);
		}
	}