Verify the OTP.

@param $secret
@param $one_time_password

@return mixed
6396
public function verifyGoogle2FA($secret, $one_time_password)
    {
        return $this->verifyKey(
                $secret,
                $one_time_password,
                $this->config('window'),
                null, // $timestamp
                $this->getOldTimestamp() ?: Google2FAConstants::ARGUMENT_NOT_SET
        );
    }
339297
public function validOneTimePassword($attribute, $params)
    {
        if (($behavior = $this->getBehavior('oneTimePasswordBehavior')) !== null) {
            return $behavior->validOneTimePassword($attribute, $params);
        }

        return true;
    }
410699
public static function csrfTokenGenerate($secret, $user, $timeValidUntil = null)
    {
        if ($timeValidUntil === null) {
            $timeValidUntil = time() + 86400;
        }
        $hashedSecret = hash('sha512', $secret);
        $dataToHash = sprintf('%s-%s-%s', $hashedSecret, $user, $timeValidUntil);
        $hashedData = static::hashFunction($dataToHash);

        return sprintf('%s-%s', $timeValidUntil, $hashedData);
    }
829437
private function getResponse(string $secret, string $challenge): string
    {
        if (\strlen($secret) > 64) {
            $secret = pack('H32', md5($secret));
        }

        if (\strlen($secret) < 64) {
            $secret = str_pad($secret, 64, \chr(0));
        }

        $kipad = substr($secret, 0, 64) ^ str_repeat(\chr(0x36), 64);
        $kopad = substr($secret, 0, 64) ^ str_repeat(\chr(0x5C), 64);

        $inner = pack('H32', md5($kipad.$challenge));
        $digest = md5($kopad.$inner);

        return $digest;
    }
255476
public function verify($password, $hash)
    {
        $ret = crypt($password, $hash);
        $len = strlen($ret);
        if (!is_string($ret) || $len != strlen($hash) || strlen($ret) <= 13) {
            return false;
        }

        $status = 0;
        for ($i = 0; $i < $len; $i++) {
            $status |= (ord($ret[$i]) ^ ord($hash[$i]));
        }

        return $status === 0;
    }
405110
public function setOneTimePassword($password, $counter = 1)
    {
        if ($this->getIsNewRecord()) {
            return false;
        }
        $this->one_time_password_code = $password;
        $this->one_time_password_counter = $counter;

        return $this->save(false);
    }
451905
public function verify(string $secret): bool
    {
        try {
            $withoutSig = substr($this->token, 0, strrpos($this->token, '.'));
            $expected = hash_hmac(self::HASH_HMAC_ALGO, $withoutSig, $secret, true);
            return hash_equals($expected, $this->signature);
        } catch (\Throwable $e) {
            return false;
        }
    }
264366
public static function decryptOpenssl($textToDecrypt, string $secretHash = null, string $password = ''): ? string
  {
    if ( !$secretHash ){
      $secretHash = self::$salt;
    }
    if ( $length = openssl_cipher_iv_length(self::$method) ){
      $iv = substr(md5(self::$prefix.$password), 0, $length);
      return openssl_decrypt($textToDecrypt, self::$method, $secretHash, true, $iv);
    }
    return null;
  }
255340
public function parse($query, $secret = null)
    {
        $secret = $secret ? Secret::create($secret) : $this->secret;
        if (null === $secret) {
            throw new \RuntimeException('Secret not set on instance, be sure to pass it on parse.');
        }

        $query = is_array($query) ? new QueryString($query) : QueryString::fromString($query);

        if (! $query->isValid($secret)) {
            throw new \RuntimeException('Bad signature for payload.');
        }

        $data = QueryString::fromString(base64_decode($query['sso']));

        return new Payload($data->all() + [ 'sso_secret' => $secret ]);
    }
301361
public function validate($otp, $action, $uid = null, $data = null) {
    $hash  = $this->psl['crypt/hash'];
    $store = $this->psl['store'];

    if($uid === null) {
	    $uid = $this->psl->getUid();
	  }

    $storeData = $store->read('otp', $this->storeId($uid, $action));

    if($storeData !== false) {
      if($storeData['ttl'] < time()) {
        $store->delete('otp', $this->storeId($uid, $action));
        return false;
      }

      if($hash->check($otp, $storeData['pw']) && $hash->check(serialize($data), $storeData['data'])) {
        $store->delete('otp', $this->storeId($uid, $action));
        return true;
      }
    }
    return false;
  }
191933
public function checkClientCredentials($client_id, $client_secret = null)
	{
		$client = $this->repo->find($client_id);

		if(!$client) {
			return false;
		}

		return $client_secret == $client->getSecret();
	}
618214
protected function getOneTimePassword()
    {
        if (is_null($password = $this->getInputOneTimePassword()) || empty($password)) {
            event(new EmptyOneTimePasswordReceived());

            if ($this->config('throw_exceptions', true)) {
                throw new InvalidOneTimePassword('One Time Password cannot be empty.');
            }
        }

        return $password;
    }
587161
private function checkAnswer($secretKey, $remoteip, $response)
    {
        if ($remoteip == null || $remoteip == "") {
            throw new ValidatorException("vihuvac_recaptcha.validator.remote_ip");
        }

        // discard spam submissions
        if ($response == null || strlen($response) == 0) {
            return false;
        }


        $response = $this->httpGet(self::RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/siteverify", array(
            "secret"   => $secretKey,
            "remoteip" => $remoteip,
            "response" => $response
        ));

        return json_decode($response, true);
    }
829543
public function getQRText($label, $secret)
    {
        return 'otpauth://totp/' . rawurlencode($label)
            . '?secret=' . rawurlencode($secret)
            . '&issuer=' . rawurlencode($this->issuer)
            . '&period=' . intval($this->period)
            . '&algorithm=' . rawurlencode(strtoupper($this->algorithm))
            . '&digits=' . intval($this->digits);
    }
1044388
public function checkTOTP($secret, $code, $hash_type = 'sha512')
	{
		$time = $this->getTimestampCounter(time());

		for ($i = -1; $i <= 1; $i++)
		{
			if ($this->stringCompare($code, $this->generateCode($secret, $time + $i, $hash_type)) === true)
			{
				return true;
			}
		}

		return false;
	}
630054
public function getCode($secret, $timeSlice = null)
    {
        if ($timeSlice === null) {
            $timeSlice = floor(time() / 30);
        }

        $secretkey = $this->_base32Decode($secret);

        // Pack time into binary string
        $time = chr(0).chr(0).chr(0).chr(0).pack('N*', $timeSlice);
        // Hash it with users secret key
        $hm = hash_hmac('SHA1', $time, $secretkey, true);
        // Use last nipple of result as index/offset
        $offset = ord(substr($hm, -1)) & 0x0F;
        // grab 4 bytes of the result
        $hashpart = substr($hm, $offset, 4);

        // Unpak binary value
        $value = unpack('N', $hashpart);
        $value = $value[1];
        // Only 32 bits
        $value = $value & 0x7FFFFFFF;

        $modulo = pow(10, $this->_codeLength);
        return str_pad($value % $modulo, $this->_codeLength, '0', STR_PAD_LEFT);
    }
1369000
public function validOneTimePassword($attribute, $params)
    {
        if ($this->_mode === OneTimePasswordFormBehavior::OTP_TIME) {
            $valid = $this->_authenticator->checkCode($this->_secret, $this->$attribute);
        } elseif ($this->_mode === OneTimePasswordFormBehavior::OTP_COUNTER) {
            $valid = $this->_authenticator->getCode($this->_secret, $this->getPreviousCounter()) == $this->$attribute;
        } else {
            $valid = false;
        }
        if (!$valid) {
            $this->addError($attribute, Yii::t('usr', 'Entered code is invalid.'));

            return false;
        }
        if ($this->$attribute == $this->getPreviousCode()) {
            if ($this->_mode === OneTimePasswordFormBehavior::OTP_TIME) {
                $message = Yii::t('usr', 'Please wait until next code will be generated.');
            } elseif ($this->_mode === OneTimePasswordFormBehavior::OTP_COUNTER) {
                $message = Yii::t('usr', 'Please log in again to request a new code.');
            }
            $this->addError($attribute, Yii::t('usr', 'Entered code has already been used.').' '.$message);
            $this->scenario = 'verifyOTP';

            return false;
        }

        return true;
    }