/** * Generates a hash code that can be used for client side validation. * @param string $code Displayed captcha code in generated image * @return int Sum of ASCII codes for all $code characters. Used for client-side validation */ public function generateValidationHash($code) { switch ($this->mode) { case CaptchaExtendedAction::MODE_DEFAULT: return parent::generateValidationHash($code); break; default: /** * We must encode result stored in session * @var CHttpSession */ $session = Yii::app()->session; $key = $this->getSessionKey(); if ($this->mode != CaptchaExtendedAction::MODE_WORDS) { // only in mode WORDS we must calculate ORD values of plain string // but we cannot use framework implementation since we need multibyte support $code = $session[$key . 'result']; } $code = preg_replace('/\\s/', '', $code); $code = urlencode($code); for ($h = 0, $i = mb_strlen($code) - 1; $i >= 0; --$i) { $chr = mb_substr($code, $i, 1, 'utf-8'); if (trim($chr) != '') { $h += ord($chr); } } return $h; } }