Validates the users two factor authentication code
@return boolean
540475
private function validateTwoFactorCode()
    {
        $otpSeed = $this->getUser()->getMetadataObject('OTPSeed', false)->value;

		if ($otpSeed === false)
			return false;
		
        $otplib = new TOTP(Cii::decrypt($otpSeed));

        return $otplib->validate($this->twoFactorCode);
    }
1314446
public function authenticate()
	{
		$user=User::model()->find('LOWER(username)=?',array(strtolower($this->username)));
		if($user===null)
			$this->errorCode=self::ERROR_USERNAME_INVALID;
		else if(!$user->validatePassword($this->password))
			$this->errorCode=self::ERROR_PASSWORD_INVALID;
		else
		{
			$this->_id=$user->id;
			$this->username=$user->username;
			$this->errorCode=self::ERROR_NONE;
		}
		return $this->errorCode==self::ERROR_NONE;
	}
136561
public function ValidateUserInput()
    {
        $bIsValid = parent::ValidateUserInput();

        if ($bIsValid) {
            $oMsgManager = TCMSMessageManager::GetInstance();

            $aDefaultVals = $this->GetDefaultUserPaymentData();

            foreach (array_keys($aDefaultVals) as $sField) {
                if (!array_key_exists($sField, $this->aPaymentUserData) || empty($this->aPaymentUserData[$sField])) {
                    $oMsgManager->AddMessage(self::MSG_MANAGER_NAME.'-'.$sField, 'ERROR-USER-REQUIRED-FIELD-MISSING');
                    $bIsValid = false;
                }
            }
        }

        return $bIsValid;
    }
1143981
public function authenticate(): bool
    {
        if (!isset($_SERVER['HTTP_AUTHORIZATION'])) {
            $this->logger->debug('skip auth adapter ['.get_class($this).'], no http authorization header found', [
                'category' => get_class($this),
            ]);

            return false;
        }

        $header = $_SERVER['HTTP_AUTHORIZATION'];
        $parts = explode(' ', $header);

        if ('Basic' === $parts[0]) {
            $this->logger->debug('found http basic authorization header', [
                'category' => get_class($this),
            ]);

            $username = $_SERVER['PHP_AUTH_USER'];
            $password = $_SERVER['PHP_AUTH_PW'];

            return $this->plainAuth($username, $password);
        }
        $this->logger->warning('http authorization header contains no basic string or invalid authentication string', [
                'category' => get_class($this),
            ]);

        return false;
    }
667785
public function validate()
    {
        $steps = [
            'PrivateKey',
            'IdpMetadata',
            'SpMetadata'
        ];

        foreach ($steps as $step) {
            $method = 'validate' . $step;
            if (!$this->$method()) {
                return false;
            }
        }

        return true;
    }
723290
public function validateToken() {
        $userData = $this->_store->userData;
        $currToken = $this->_store->token;
        $checkToken = $this->createToken(serialize($userData));
        return $checkToken === $currToken;
    }
432637
public function validate() {
        global $DB;
        $params = array_keys($this->params);
        $method = ($this->method == BADGE_CRITERIA_AGGREGATION_ALL);
        $singleparam = (count($params) == 1);

        foreach ($params as $param) {
            // Perform check if there only one parameter with any type of aggregation,
            // Or there are more than one parameter with aggregation ALL.
            if (($singleparam || $method) && !$DB->record_exists('cohort', array('id' => $param))) {
                return array(false, get_string('error:invalidparamcohort', 'badges'));
            }
        }

        return array(true, '');
    }
141528
public function ValidateUserInput()
    {
        $bIsValid = parent::ValidateUserInput();

        if ($bIsValid) {
            $oMsgManager = TCMSMessageManager::GetInstance();
            $required = array('iban');
            if (!self::isGermanIBAN($this->aPaymentUserData['iban'])) {
                $required[] = 'bic';
            }
            foreach ($required as $field) {
                if (!isset($this->aPaymentUserData[$field]) || empty($this->aPaymentUserData[$field])) {
                    $oMsgManager->AddMessage(self::MSG_MANAGER_NAME.'-'.$field, 'ERROR-USER-REQUIRED-FIELD-MISSING');
                    $bIsValid = false;
                }
            }
        }
        if ($bIsValid) {
            $bIsValid = $this->validateIBAN($this->aPaymentUserData['iban']) && $bIsValid;
            $bIsValid = $this->validateBIC($this->aPaymentUserData['bic']) && $bIsValid;
        }

        return $bIsValid;
    }
1181224
protected function validatePasswordLengthUser()
    {
        $field = 'password';

        if ($this->isExcluded($field) || $this->isError($field)) {
            return null;
        }

        $value = $this->getSubmitted($field);

        if ($this->isUpdating() && (!isset($value) || $value === '')) {
            return null;
        }

        $length = mb_strlen($value);
        list($min, $max) = $this->user->getPasswordLength();

        if ($length < $min || $length > $max) {
            $this->setErrorLengthRange($field, $this->translation->text('Password'), $min, $max);
            return false;
        }

        return true;
    }
996661
public function valid()
        {
            // Return true if and only if all parts of the URI have passed validation
            return $this->validateUsername()
               && $this->validatePassword()
               && $this->validateHost()
               && $this->validatePort()
               && $this->validatePath()
               && $this->validateQuery()
               && $this->validateFragment();
        }
514708
public function valid()
    {
        $isValid = $this->isFlagSet(self::STATUS_VALID);
        $subscriptionFlags = self::STATUS_SUBSCRIBED | self::STATUS_PSUBSCRIBED;
        $hasSubscriptions = ($this->statusFlags & $subscriptionFlags) > 0;

        return $isValid && $hasSubscriptions;
    }
174892
public function authenticate($force=false)
	{
        // Setup everything first
		$this->setup($force);

        // If something bad happened during the setup process, immediately bail with the error code
        if ($this->errorCode != NULL)
            return !$this->errorCode;

        // Validate the users password
        $this->validatePassword();

        // If this user has 5 or more failed password attempts
        if ($this->_attempts->value >= 5)
        {
            // And if they the updated time is still more than 15 minutes ago
            if ((strtotime($this->_attempts->updated) + strtotime("+15 minutes")) >= time())
            {
                // Resave the attempts model so that the updated time is reset
                $this->_attempts->save();

                // Throw an unknown identity error
                $this->errorCode = self::ERROR_UNKNOWN_IDENTITY;
            }
            else
            {
                // Automatically re-adjust the lockout time if this has passed.
                $this->_attempts->value = 0;
                $this->_attempts->save();
            }
        }

        // If the user needs two factor authentication
        if ($this->getUser()->needsTwoFactorAuth())
        {
            // If the code isn't supplied, throw an error
            if ($this->twoFactorCode === false)
               $this->errorCode = self::REQUIRE_TWO_FACTOR_AUTH;
            else
            {
                // If the 2fa code is supplied, verify it
                if (!$this->validateTwoFactorCode())
                    $this->errorCode = self::INVALID_TWO_FACTOR_AUTH;
            } 
        }

        // At this point, we should should know if the validation has succeeded or not. If the errorCode has been altered, immediately bail
        if ($this->errorCode != NULL)
            return !$this->errorCode;
        else
            $this->setIdentity();

        return !$this->errorCode;
    }
380079
protected function validateSettings()
    {
        $this->setSubmitted('settings');

        $this->validateElement('limit', 'regexp', '/^[\d]{1,3}$/');
        $this->validateElement('cache', 'regexp', '/^[\d]{1,8}$/');
        $this->validateElement('credential_id', 'regexp', '/^[\d]{1,10}$/');

        $this->validateGaProfileSettings();

        return !$this->hasErrors();
    }
366454
public function validateCsrf()
    {
        $tokenService = $this->getServiceLocator()->get(TokenService::SERVICE_ID);

        $tokenName = $tokenService->getTokenName();
        $token = $this->getRequestParameter($tokenName);

        if ( $tokenService->checkToken($token) ) {
            $tokenService->revokeToken($token);
            $newToken = $tokenService->createToken();
            $this->setCookie($tokenName, $newToken, null, '/');
            return true;
        }

        \common_Logger::w('Csrf validation failed');
        throw new \common_exception_Unauthorized();
    }
428395
public function authenticate()
    {
        $result = false;

        if (isset($_GET['code'])) {
            $params = array(
                'grant_type' => 'authorization_code',
                'code' => $_GET['code'],
                'client_id' => $this->clientId,
                'client_secret' => $this->clientSecret
            );

            $tokenInfo = $this->post('https://oauth.yandex.ru/token', $params);

            if (isset($tokenInfo['access_token'])) {
                $params = array(
                    'format' => 'json',
                    'oauth_token' => $tokenInfo['access_token']
                );

                $userInfo = $this->get('https://login.yandex.ru/info', $params);

                if (isset($userInfo['id'])) {
                    $this->userInfo = $userInfo;
                    $result = true;
                }
            }
        }

        return $result;
    }
295453
protected function validSecret()
    {
        // this method is intentionally broken in two pieces
        // so the logic will be loud and clear.

        // is the secret empty?
        if (empty($this->secret)) {
            return false;
        }

        // created a hex representation of the secret.
        $hexRepresentation = bin2hex($this->secret);

        // check for the secret's hex representation length...
        // hex size is deterministic, it's a way of counting bytes from binary
        // ( SORT OF)
        // in any case, the length will double of the binary random generated secret.
        // 16 bytes secret will have a hex of length 32
        // 32 bytes secret will have a hex of length 64
        // 64 bytes secret will have a hex of length 128
        // you get it right?
        if ((Str::length($hexRepresentation) / 2) < 16) {
            // the minimum secret size should be 16
            // so return false in case the secret
            // is shorter than that.
            return false;
        }

        // after all this checks, declare the secret valid (finally).
        return true;
    }
335134
final public function validate(): bool
    {
        // validate csrf token if required
        if ($this->_tokenRequired && !$this->_tokenOk) {
            App::$Session->getFlashBag()->add('warning', __('Hack attention: security token is wrong!'));
            return false;
        }
        // get all rules as array from method rules()
        $rules = $this->rules();
        // get default values of attributes
        $defaultAttr = $this->getAllProperties();

        // start validation: on this step class attribute values will be changed to input data if it valid
        $success = $this->runValidate($rules);

        // get not-passed validation fields as array
        $badAttributes = $this->getBadAttributes();
        // prevent warnings
        if (Any::isArray($badAttributes) && count($badAttributes) > 0) {
            foreach ($badAttributes as $attr) {
                if (Str::contains('.', $attr)) { // sounds like dot-separated array attr
                    $attrName = strstr($attr, '.', true); // get attr name
                    $attrArray = trim(strstr($attr, '.'), '.'); // get dot-based array path

                    $defaultValue = new DotData($defaultAttr); // load default attr

                    $dotData = new DotData($this->{$attrName}); // load local attr variable
                    $dotData->set($attrArray, $defaultValue->get($attr)); // set to local prop. variable default value

                    $this->{$attrName} = $dotData->export(); // export to model
                } else {
                    $this->{$attr} = $defaultAttr[$attr]; // just set ;)
                }
                // add message about wrong attribute to session holder, later display it
                $attrLabel = $attr;
                if ($this->getLabel($attr) !== null) {
                    $attrLabel = $this->getLabel($attr);
                }

                App::$Session->getFlashBag()->add('warning', __('Field "%field%" is incorrect', ['field' => $attrLabel]));
            }
        }

        return $success;
    }