ManaPHP\Security\Captcha::_verify PHP Method

_verify() protected method

protected _verify ( string $code, boolean $isTry ) : void
$code string
$isTry boolean
return void
    protected function _verify($code, $isTry)
    {
        if (!$this->session->has($this->_sessionVar)) {
            throw new CaptchaException('captcha is not exist in server');
        }
        $sessionVar = $this->session->get($this->_sessionVar);
        if ($isTry) {
            if (isset($sessionVar['try_verified_time'])) {
                $this->session->remove($this->_sessionVar);
                throw new CaptchaException('captcha has been tried');
            } else {
                $sessionVar['try_verified_time'] = time();
                $this->session->set($this->_sessionVar, $sessionVar);
            }
        } else {
            $this->session->remove($this->_sessionVar);
        }
        if (time() - $sessionVar['created_time'] < $this->_minInterval) {
            throw new CaptchaException('captcha verification is too frequency');
        }
        if (time() - $sessionVar['created_time'] > $sessionVar['ttl']) {
            throw new CaptchaException('captcha is expired');
        }
        if (strtolower($sessionVar['code']) !== strtolower($code)) {
            throw new CaptchaException('captcha is not match');
        }
    }