4if (!class_exists(
"CCaptcha")):
11 var $ttfFilesPath =
"/bitrix/modules/main/fonts";
12 var $arTTFFiles = [
"font.ttf"];
13 var $textAngleFrom = -20;
14 var $textAngleTo = 20;
16 var $textDistanceFrom = 27;
17 var $textDistanceTo = 32;
18 var $textFontSize = 20;
19 var $bTransparentText =
true;
20 var $transparentTextPercent = 10;
21 var $arTextColor = [[0, 100], [0, 100], [0, 100]];
22 var $arBGColor = [[255, 255], [255, 255], [255, 255]];
23 var $arRealBGColor =
false;
24 var $numEllipses = 100;
25 var $arEllipseColor = [[127, 255], [127, 255], [127, 255]];
27 var $arLineColor = [[110, 250], [110, 250], [110, 250]];
28 var $bLinesOverText =
false;
29 var $arBorderColor = [0, 0, 0];
30 var $bWaveTransformation =
false;
31 var $bEmptyText =
false;
33 'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'J',
'K',
'L',
'M',
34 'N',
'P',
'Q',
'R',
'S',
'T',
'W',
'X',
'Y',
'Z',
35 '2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
45 $this->bTransparentText = $this->transparentTextPercent > 0;
47 COption::GetOptionString(
"main",
"CAPTCHA_arBGColor_1",
"FFFFFF"),
48 COption::GetOptionString(
"main",
"CAPTCHA_arBGColor_2",
"FFFFFF")
50 $this->SetEllipsesNumber(
51 COption::GetOptionInt(
"main",
"CAPTCHA_numEllipses", 100)
53 $this->SetEllipseColorRGB(
54 COption::GetOptionString(
"main",
"CAPTCHA_arEllipseColor_1",
"7F7F7F"),
55 COption::GetOptionString(
"main",
"CAPTCHA_arEllipseColor_2",
"FFFFFF")
57 $this->SetLinesOverText(
58 COption::GetOptionString(
"main",
"CAPTCHA_bLinesOverText",
"N") ===
"Y"
60 $this->SetLinesNumber(
61 COption::GetOptionInt(
"main",
"CAPTCHA_numLines", 20)
63 $this->SetLineColorRGB(
64 COption::GetOptionString(
"main",
"CAPTCHA_arLineColor_1",
"6E6E6E"),
65 COption::GetOptionString(
"main",
"CAPTCHA_arLineColor_2",
"FAFAFA")
67 $this->SetTextWriting(
68 COption::GetOptionInt(
"main",
"CAPTCHA_textAngel_1", -20),
69 COption::GetOptionInt(
"main",
"CAPTCHA_textAngel_2", 20),
70 COption::GetOptionInt(
"main",
"CAPTCHA_textStartX", 7),
71 COption::GetOptionInt(
"main",
"CAPTCHA_textDistance_1", 27),
72 COption::GetOptionInt(
"main",
"CAPTCHA_textDistance_2", 32),
73 COption::GetOptionInt(
"main",
"CAPTCHA_textFontSize", 20)
75 $this->SetTextColorRGB(
76 COption::GetOptionString(
"main",
"CAPTCHA_arTextColor_1",
"000000"),
77 COption::GetOptionString(
"main",
"CAPTCHA_arTextColor_2",
"646464")
79 $this->SetWaveTransformation(
80 COption::GetOptionString(
"main",
"CAPTCHA_bWaveTransformation",
"N") ===
"Y"
83 COption::GetOptionString(
"main",
"CAPTCHA_bEmptyText",
"N") ===
"Y"
85 $this->SetBorderColorRGB(
86 COption::GetOptionString(
"main",
"CAPTCHA_arBorderColor",
"000000")
89 explode(
",", COption::GetOptionString(
"main",
"CAPTCHA_arTTFFiles",
"font.ttf"))
94 for (
$i = 0,
$n = mb_strlen($strChars);
$i <
$n;
$i++)
96 $arChars[] = mb_substr($strChars,
$i, 1);
98 $this->SetCodeChars($arChars);
102 function SetImageSize(
$width, $height)
105 $height = intval($height);
109 $this->imageWidth =
$width;
114 $this->imageHeight = $height;
118 function SetCodeLength($length)
120 $length = intval($length);
124 $this->codeLength = $length;
128 function SetTTFFontsPath($ttfFilesPath)
130 if ($ttfFilesPath <>
'')
132 $filename = trim(str_replace(
"\\",
"/", trim($ttfFilesPath)),
"/");
134 if (mb_strlen($FILE_NAME) > 1 && is_dir(
$_SERVER[
"DOCUMENT_ROOT"] . $FILE_NAME))
136 $this->ttfFilesPath = $FILE_NAME;
141 function GetTTFFontsPath()
143 return $this->ttfFilesPath;
146 function SetTTFFonts($arFonts)
148 if (!is_array($arFonts) || empty($arFonts))
153 $this->arTTFFiles = $arFonts;
156 function SetTextWriting($angleFrom, $angleTo, $startX, $distanceFrom, $distanceTo,
$fontSize)
158 $angleFrom = intval($angleFrom);
159 $angleTo = intval($angleTo);
160 $startX = intval($startX);
161 $distanceFrom = intval($distanceFrom);
162 $distanceTo = intval($distanceTo);
165 $this->textAngleFrom = $angleFrom;
166 $this->textAngleTo = $angleTo;
170 $this->textStartX = $startX;
173 if ($distanceFrom <> 0)
175 $this->textDistanceFrom = $distanceFrom;
178 if ($distanceTo <> 0)
180 $this->textDistanceTo = $distanceTo;
189 function SetTextTransparent($bTransparentText, $transparentTextPercent = 10)
191 $this->bTransparentText = (bool)$bTransparentText;
192 $this->transparentTextPercent = intval($transparentTextPercent);
195 function SetColor($arColor)
197 if (!is_array($arColor) ||
count($arColor) != 3)
203 $bCorrectColor =
true;
205 for (
$i = 0;
$i < 3;
$i++)
207 if (!is_array($arColor[
$i]))
209 $arColor[
$i] = [$arColor[
$i]];
212 for ($j = 0; $j < 2; $j++)
216 if (!array_key_exists($j, $arColor[
$i]))
218 $arColor[
$i][$j] = $arColor[
$i][$j - 1];
222 $arColor[
$i][$j] = intval($arColor[
$i][$j]);
223 if ($arColor[
$i][$j] < 0 || $arColor[
$i][$j] > 255)
225 $bCorrectColor =
false;
231 if ($arColor[
$i][$j] < $arColor[
$i][$j - 1])
233 $bCorrectColor =
false;
238 $arNewColor[
$i][$j] = $arColor[
$i][$j];
255 function SetBGColor($arColor)
257 if ($arNewColor = $this->SetColor($arColor))
259 $this->arBGColor = $arNewColor;
260 $this->arRealBGColor =
false;
264 function SetBGColorRGB($color_1, $color_2)
266 if (preg_match(
"/^[0-9A-Fa-f]{6}$/", $color_1) && preg_match(
"/^[0-9A-Fa-f]{6}$/", $color_1))
269 [hexdec(mb_substr($color_1, 0, 2)), hexdec(mb_substr($color_2, 0, 2))],
270 [hexdec(mb_substr($color_1, 2, 2)), hexdec(mb_substr($color_2, 2, 2))],
271 [hexdec(mb_substr($color_1, 4, 2)), hexdec(mb_substr($color_2, 4, 2))],
273 $this->SetBGColor($arColor);
277 function SetTextColor($arColor)
279 if ($arNewColor = $this->SetColor($arColor))
281 $this->arTextColor = $arNewColor;
285 function SetTextColorRGB($color_1, $color_2)
287 if (preg_match(
"/^[0-9A-Fa-f]{6}$/", $color_1) && preg_match(
"/^[0-9A-Fa-f]{6}$/", $color_1))
290 [hexdec(mb_substr($color_1, 0, 2)), hexdec(mb_substr($color_2, 0, 2))],
291 [hexdec(mb_substr($color_1, 2, 2)), hexdec(mb_substr($color_2, 2, 2))],
292 [hexdec(mb_substr($color_1, 4, 2)), hexdec(mb_substr($color_2, 4, 2))],
294 $this->SetTextColor($arColor);
298 function SetEllipseColor($arColor)
300 if ($arNewColor = $this->SetColor($arColor))
302 $this->arEllipseColor = $arNewColor;
306 function SetEllipseColorRGB($color_1, $color_2)
308 if (preg_match(
"/^[0-9A-Fa-f]{6}$/", $color_1) && preg_match(
"/^[0-9A-Fa-f]{6}$/", $color_1))
311 [hexdec(mb_substr($color_1, 0, 2)), hexdec(mb_substr($color_2, 0, 2))],
312 [hexdec(mb_substr($color_1, 2, 2)), hexdec(mb_substr($color_2, 2, 2))],
313 [hexdec(mb_substr($color_1, 4, 2)), hexdec(mb_substr($color_2, 4, 2))],
315 $this->SetEllipseColor($arColor);
319 function SetLineColor($arColor)
321 if ($arNewColor = $this->SetColor($arColor))
323 $this->arLineColor = $arNewColor;
327 function SetLineColorRGB($color_1, $color_2)
329 if (preg_match(
"/^[0-9A-Fa-f]{6}$/", $color_1) && preg_match(
"/^[0-9A-Fa-f]{6}$/", $color_1))
332 [hexdec(mb_substr($color_1, 0, 2)), hexdec(mb_substr($color_2, 0, 2))],
333 [hexdec(mb_substr($color_1, 2, 2)), hexdec(mb_substr($color_2, 2, 2))],
334 [hexdec(mb_substr($color_1, 4, 2)), hexdec(mb_substr($color_2, 4, 2))],
336 $this->SetLineColor($arColor);
340 function SetBorderColor($arColor)
342 if ($arNewColor = $this->SetColor($arColor))
344 $this->arBorderColor = $arNewColor;
348 function SetBorderColorRGB($color)
350 if (preg_match(
"/^[0-9A-Fa-f]{6}$/", $color))
353 hexdec(mb_substr($color, 0, 2)),
354 hexdec(mb_substr($color, 2, 2)),
355 hexdec(mb_substr($color, 4, 2)),
357 $this->SetBorderColor($arColor);
361 function SetEllipsesNumber($num)
363 $this->numEllipses = intval($num);
366 function SetLinesNumber($num)
368 $this->numLines = intval($num);
371 function SetLinesOverText($bLinesOverText)
373 $this->bLinesOverText = (bool)$bLinesOverText;
376 function SetCodeChars($arChars)
378 if (is_array($arChars) && !empty($arChars))
380 $this->arChars = $arChars;
384 function SetWaveTransformation($bWaveTransformation)
386 $this->bWaveTransformation = (bool)$bWaveTransformation;
389 function SetEmptyText($bEmptyText)
391 $this->bEmptyText = (bool)$bEmptyText;
395 function GetColor($arColor)
405 function InitImage(
$width =
false, $height =
false)
409 $width = $this->imageWidth;
413 $height = $this->imageHeight;
415 $image = imagecreatetruecolor(
$width, $height);
416 if (!$this->arRealBGColor)
418 $this->arRealBGColor = $this->GetColor($this->arBGColor);
420 $bgColor = imagecolorallocate($image, $this->arRealBGColor[0], $this->arRealBGColor[1], $this->arRealBGColor[2]);
421 imagefilledrectangle($image, 0, 0, imagesx($image), imagesy($image), $bgColor);
425 function CreateImage()
427 $this->image = $this->InitImage();
429 $this->DrawEllipses();
431 if (!$this->bLinesOverText)
438 if ($this->bLinesOverText)
443 if ($this->bWaveTransformation)
448 $arBorderColor = $this->GetColor($this->arBorderColor);
449 $borderColor = imagecolorallocate($this->image, $arBorderColor[0], $arBorderColor[1], $arBorderColor[2]);
450 imageline($this->image, 0, 0, $this->imageWidth - 1, 0, $borderColor);
451 imageline($this->image, 0, 0, 0, $this->imageHeight - 1, $borderColor);
452 imageline($this->image, $this->imageWidth - 1, 0, $this->imageWidth - 1, $this->imageHeight - 1, $borderColor);
453 imageline($this->image, 0, $this->imageHeight - 1, $this->imageWidth - 1, $this->imageHeight - 1, $borderColor);
456 function CreateImageError($arMsg)
458 $this->image = imagecreate($this->imageWidth, $this->imageHeight);
459 $textColor = imagecolorallocate($this->image, 255, 255, 255);
461 if (!is_array($arMsg))
470 if (trim($arMsg[
$i]) <>
'')
473 imagestring($this->image, 3, 5, $y, $arMsg[
$i], $textColor);
480 imagestring($this->image, 3, 5, 5,
"Error!", $textColor);
481 imagestring($this->image, 3, 5, 20,
"Reload the page!", $textColor);
488 $img2 = $this->InitImage();
492 $rand1 = mt_rand(700000, 1000000) / 15000000;
493 $rand2 = mt_rand(700000, 1000000) / 15000000;
494 $rand3 = mt_rand(700000, 1000000) / 15000000;
495 $rand4 = mt_rand(700000, 1000000) / 15000000;
497 $rand5 = mt_rand(0, 3141592) / 1000000;
498 $rand6 = mt_rand(0, 3141592) / 1000000;
499 $rand7 = mt_rand(0, 3141592) / 1000000;
500 $rand8 = mt_rand(0, 3141592) / 1000000;
502 $rand9 = mt_rand(400, 600) / 500;
503 $rand10 = mt_rand(400, 600) / 200;
505 $height = $this->imageHeight;
506 $height_1 = $height - 1;
507 $width = $this->imageWidth;
510 for ($x = 0; $x <
$width; $x++)
512 for ($y = 0; $y < $height; $y++)
515 $sx = $x + (sin($x * $rand1 + $rand5) + sin($y * $rand3 + $rand6)) * $rand9;
516 $sy = $y + (sin($x * $rand2 + $rand7) + sin($y * $rand4 + $rand8)) * $rand10;
518 if ($sx < 0 || $sy < 0 || $sx >= $width_1 || $sy >= $height_1)
525 $rgb = imagecolorat($img, $sx, $sy);
526 $color_r = ($rgb >> 16) & 0xFF;
527 $color_g = ($rgb >> 8) & 0xFF;
528 $color_b = $rgb & 0xFF;
530 $rgb = imagecolorat($img, $sx + 1, $sy);
531 $color_x_r = ($rgb >> 16) & 0xFF;
532 $color_x_g = ($rgb >> 8) & 0xFF;
533 $color_x_b = $rgb & 0xFF;
535 $rgb = imagecolorat($img, $sx, $sy + 1);
536 $color_y_r = ($rgb >> 16) & 0xFF;
537 $color_y_g = ($rgb >> 8) & 0xFF;
538 $color_y_b = $rgb & 0xFF;
540 $rgb = imagecolorat($img, $sx + 1, $sy + 1);
541 $color_xy_r = ($rgb >> 16) & 0xFF;
542 $color_xy_g = ($rgb >> 8) & 0xFF;
543 $color_xy_b = $rgb & 0xFF;
546 $frsx = $sx - floor($sx);
547 $frsy = $sy - floor($sy);
551 $i11 = $frsx1 * $frsy1;
552 $i01 = $frsx * $frsy1;
553 $i10 = $frsx1 * $frsy;
554 $i00 = $frsx * $frsy;
555 $red = floor($color_r * $i11 +
560 $green = floor($color_g * $i11 +
565 $blue = floor($color_b * $i11 +
570 imagesetpixel($img2, $x, $y, imagecolorallocate($img2, $red, $green, $blue));
573 $this->image = $img2;
578 $sx = imagesx($this->image) - 1;
579 $sy = imagesy($this->image) - 1;
581 $backup = imagecreatetruecolor($sx, $sy);
582 imagealphablending($backup,
false);
583 imagecopy($backup, $this->image, 0, 0, 0, 0, $sx, $sy);
585 $white = imagecolorallocate($this->image, 255, 255, 255);
586 $bgColor = imagecolorallocate($this->image, $this->arRealBGColor[0], $this->arRealBGColor[1], $this->arRealBGColor[2]);
588 for ($x = 1; $x < $sx; $x++)
590 for ($y = 1; $y < $sy; $y++)
592 $c1 = imagecolorat($backup, $x - 1, $y);
593 if ($c1 != $white && $c1 != $bgColor)
595 $c2 = imagecolorat($backup, $x + 1, $y);
598 $c3 = imagecolorat($backup, $x, $y - 1);
601 $c4 = imagecolorat($backup, $x, $y + 1);
604 imagesetpixel($this->image, $x, $y, $bgColor);
612 if (function_exists(
'imageconvolution'))
614 $gaussian = [[1.0, 1.0, 1.0], [1.0, 7.0, 1.0], [1.0, 1.0, 1.0]];
615 imageconvolution($this->image, $gaussian, 15, 0);
622 imageconvolution($this->image, $mask, 1, 0);
626 function DestroyImage()
628 imagedestroy($this->image);
633 imagejpeg($this->image);
638 $alpha = ($this->bTransparentText ? floor($this->transparentTextPercent / 100 * 127) : 0);
640 $bPrecise = $this->textDistanceFrom < 0 && $this->textDistanceTo < 0;
645 $bg_color_hex = $this->arRealBGColor[0] << 16 | $this->arRealBGColor[1] << 8 | $this->arRealBGColor[2];
647 (!$bg_color_hex >> 16) & 0xFF,
648 (!$bg_color_hex >> 8) & 0xFF,
649 (!$bg_color_hex) & 0xFF,
656 for (
$i = 0;
$i < $this->codeLength;
$i++)
658 $char = mb_substr($this->code,
$i, 1);
661 $ttfFile =
$_SERVER[
"DOCUMENT_ROOT"] . $this->ttfFilesPath .
"/" . $this->arTTFFiles[rand(1,
count($this->arTTFFiles)) - 1];
662 $angle = rand($this->textAngleFrom, $this->textAngleTo);
664 $bounds = imagettfbbox($this->textFontSize, $angle, $ttfFile, $utf);
666 $height = max($bounds[1], $bounds[3], $bounds[5], $bounds[7]) - min($bounds[1], $bounds[3], $bounds[5], $bounds[7]);
667 $width = max($bounds[0], $bounds[2], $bounds[4], $bounds[6]) - min($bounds[0], $bounds[2], $bounds[4], $bounds[6]);
669 $y = $height + rand(0, ($this->imageHeight - $height) * 0.9);
678 $img = $this->InitImage(
$width, $this->imageHeight);
679 $tmp = imagecolorallocate($img, $not_bg_color[0], $not_bg_color[1], $not_bg_color[2]);
680 $dx = -min($bounds[0], $bounds[2], $bounds[4], $bounds[6]);
681 imagettftext($img, $this->textFontSize, $angle, $dx, $y,
$tmp, $ttfFile, $utf);
683 for ($yy = 0; $yy < $this->imageHeight; $yy++)
685 $arLeftBounds[$yy] = 0;
686 for ($xx = 0; $xx <
$width; $xx++)
688 $rgb = imagecolorat($img, $xx, $yy);
689 if ($rgb !== $bg_color_hex)
691 $arLeftBounds[$yy] = $xx;
696 $arRightBounds[$yy] = 0;
697 if ($arLeftBounds[$yy] > 0)
699 for ($xx =
$width; $xx > 0; $xx--)
701 $rgb = imagecolorat($img, $xx - 1, $yy);
702 if ($rgb !== $bg_color_hex)
704 $arRightBounds[$yy] = $xx - 1;
719 for ($yy = 0; $yy < $this->imageHeight; $yy++)
721 if ($arPos[
$i - 1][6][$yy] > 0 && $arLeftBounds[$yy] > 0)
723 $arDX[$yy] = ($arPos[
$i - 1][6][$yy] - $arPos[
$i - 1][7]) - ($arLeftBounds[$yy] - $dx);
727 $arDX[$yy] = $arPos[
$i - 1][5][$yy] - $arPos[
$i - 1][7];
730 $x += max($arDX) + (rand($this->textDistanceFrom, $this->textDistanceTo));
734 $x += rand($this->textDistanceFrom, $this->textDistanceTo);
739 $x = rand($this->textStartX / 2, $this->textStartX * 2);
756 foreach ($arPos as $pos)
758 $arTextColor = $this->GetColor($this->arTextColor);
760 if ($this->bTransparentText)
762 $color = imagecolorallocatealpha($this->image, $arTextColor[0], $arTextColor[1], $arTextColor[2], $alpha);
766 $color = imagecolorallocate($this->image, $arTextColor[0], $arTextColor[1], $arTextColor[2]);
769 $bounds = imagettftext($this->image, $this->textFontSize, $pos[0], $pos[1], $pos[2], $color, $pos[3], $pos[8]);
771 $x2 = $pos[1] + ($bounds[2] - $bounds[0]);
774 if ($this->bEmptyText)
782 function DrawEllipses()
784 if ($this->numEllipses > 0)
786 for (
$i = 0;
$i < $this->numEllipses;
$i++)
788 $arEllipseColor = $this->GetColor($this->arEllipseColor);
789 $color = imagecolorallocate($this->image, $arEllipseColor[0], $arEllipseColor[1], $arEllipseColor[2]);
790 imagefilledellipse($this->image, round(rand(0, $this->imageWidth)), round(rand(0, $this->imageHeight)), round(rand(0, $this->imageWidth / 8)), round(rand(0, $this->imageHeight / 2)), $color);
797 if ($this->numLines > 0)
799 for (
$i = 0;
$i < $this->numLines;
$i++)
801 $arLineColor = $this->GetColor($this->arLineColor);
802 $color = imagecolorallocate($this->image, $arLineColor[0], $arLineColor[1], $arLineColor[2]);
803 imageline($this->image, rand(1, $this->imageWidth), rand(1, $this->imageHeight / 2), rand(1, $this->imageWidth), rand($this->imageHeight / 2, $this->imageHeight), $color);
811 header(
"Expires: Sun, 1 Jan 2000 12:00:00 GMT");
812 header(
"Last-Modified: " . gmdate(
"D, d M Y H:i:s") .
"GMT");
813 header(
"Cache-Control: no-store, no-cache, must-revalidate");
814 header(
"Cache-Control: post-check=0, pre-check=0",
false);
815 header(
"Pragma: no-cache");
816 header(
"Content-Type: image/jpeg");
817 $this->CreateImage();
819 $this->DestroyImage();
822 function OutputError()
824 header(
"Expires: Sun, 1 Jan 2000 12:00:00 GMT");
825 header(
"Last-Modified: " . gmdate(
"D, d M Y H:i:s") .
"GMT");
826 header(
"Cache-Control: no-store, no-cache, must-revalidate");
827 header(
"Cache-Control: post-check=0, pre-check=0",
false);
828 header(
"Pragma: no-cache");
829 header(
"Content-Type: image/jpeg");
831 $numArgs = func_num_args();
834 $arMsg = func_get_arg(0);
841 $this->CreateImageError($arMsg);
843 $this->DestroyImage();
849 if (!defined(
"CAPTCHA_COMPATIBILITY"))
851 CCaptcha::SetCaptchaCode();
858 for (
$i = 0;
$i < $this->codeLength;
$i++)
860 $this->code .= $this->arChars[rand(1,
$max) - 1];
865 $session = \Bitrix\Main\Application::getInstance()->getSession();
866 $session[
"CAPTCHA_CODE"][$this->sid] =
$this->code;
869 function SetCodeCrypt()
871 if (!defined(
"CAPTCHA_COMPATIBILITY"))
873 CCaptcha::SetCaptchaCode();
880 for (
$i = 0;
$i < $this->codeLength;
$i++)
882 $this->code .= $this->arChars[rand(1,
$max) - 1];
885 $session = \Bitrix\Main\Application::getInstance()->getSession();
886 if (!$session->get(
"CAPTCHA_PASSWORD"))
888 $session[
"CAPTCHA_PASSWORD"] =
randString(10);
891 $this->codeCrypt = $this->CryptData($this->code,
"E", $session[
"CAPTCHA_PASSWORD"]);
894 function SetCaptchaCode($sid =
false)
899 for (
$i = 0;
$i < $this->codeLength;
$i++)
901 $this->code .= $this->arChars[rand(1,
$max) - 1];
904 $this->sid = $sid ===
false ? $this->Generate32RandomString() : $sid;
908 "CODE" => $this->code,
914 function Generate32RandomString()
916 $prefix = (defined(
"BX_CLUSTER_GROUP") ? BX_CLUSTER_GROUP :
"0");
917 return mb_substr($prefix . md5(uniqid()), 0, 32);
920 function InitCaptchaCode($sid)
924 $res =
$DB->Query(
"SELECT CODE FROM b_captcha WHERE ID = '" .
$DB->ForSQL($sid, 32) .
"' ");
930 $this->code =
$ar[
"CODE"];
932 $this->codeLength = mb_strlen($this->code);
937 function InitCode($sid)
939 if (!defined(
"CAPTCHA_COMPATIBILITY"))
941 return CCaptcha::InitCaptchaCode($sid);
944 $session = \Bitrix\Main\Application::getInstance()->getSession();
945 if (!is_array($session[
"CAPTCHA_CODE"]) || empty($session[
"CAPTCHA_CODE"]))
950 if (!array_key_exists($sid, $session[
"CAPTCHA_CODE"]))
955 $this->code = $session[
"CAPTCHA_CODE"][$sid];
957 $this->codeLength = mb_strlen($this->code);
962 function InitCodeCrypt($codeCrypt)
964 if (!defined(
"CAPTCHA_COMPATIBILITY"))
966 return CCaptcha::InitCaptchaCode($codeCrypt);
969 if ($codeCrypt ==
'')
974 $session = \Bitrix\Main\Application::getInstance()->getSession();
975 if (!$session->get(
"CAPTCHA_PASSWORD"))
980 $this->codeCrypt = $codeCrypt;
981 $this->code = $this->CryptData($codeCrypt,
"D", $session[
"CAPTCHA_PASSWORD"]);
982 $this->codeLength = mb_strlen($this->code);
992 function GetCodeCrypt()
994 if (!defined(
"CAPTCHA_COMPATIBILITY"))
999 return $this->codeCrypt;
1002 function CheckCaptchaCode($userCode, $sid, $bUpperCode =
true)
1006 if (!is_string($userCode) || $userCode ==
'' || !is_string($sid) || $sid ==
'')
1013 $userCode = mb_strtoupper($userCode);
1016 $res =
$DB->Query(
"SELECT CODE FROM b_captcha WHERE ID = '" .
$DB->ForSQL($sid, 32) .
"' ");
1022 if (
$ar[
"CODE"] != $userCode)
1027 CCaptcha::Delete($sid);
1032 function CheckCode($userCode, $sid, $bUpperCode =
true)
1034 if (!defined(
"CAPTCHA_COMPATIBILITY"))
1036 return CCaptcha::CheckCaptchaCode($userCode, $sid, $bUpperCode);
1039 if (!is_string($userCode) || $userCode ==
'' || !is_string($sid) || $sid ==
'')
1044 $session = \Bitrix\Main\Application::getInstance()->getSession();
1045 if (empty($session[
"CAPTCHA_CODE"]) || !is_array($session[
"CAPTCHA_CODE"]))
1050 if (!isset($session[
"CAPTCHA_CODE"][$sid]))
1057 $userCode = mb_strtoupper($userCode);
1060 if ($session[
"CAPTCHA_CODE"][$sid] != $userCode)
1065 unset($session[
"CAPTCHA_CODE"][$sid]);
1070 function CheckCodeCrypt($userCode, $codeCrypt,
$password =
"", $bUpperCode =
true)
1072 if (!defined(
"CAPTCHA_COMPATIBILITY"))
1074 return CCaptcha::CheckCaptchaCode($userCode, $codeCrypt, $bUpperCode);
1077 if ($codeCrypt ==
'')
1082 $session = \Bitrix\Main\Application::getInstance()->getSession();
1083 if (!$session->get(
"CAPTCHA_PASSWORD"))
1090 $userCode = mb_strtoupper($userCode);
1093 $code = $this->CryptData($codeCrypt,
"D", $session[
"CAPTCHA_PASSWORD"]);
1095 if (
$code != $userCode)
1118 $pwdLength = mb_strlen($pwdString);
1120 for (
$i = 0;
$i <= 255;
$i++)
1122 $key[
$i] = ord(mb_substr($pwdString, (
$i % $pwdLength), 1));
1127 for (
$i = 0;
$i <= 255;
$i++)
1129 $x = ($x + $box[
$i] +
$key[
$i]) % 256;
1130 $temp_swap = $box[
$i];
1131 $box[
$i] = $box[$x];
1132 $box[$x] = $temp_swap;
1139 $a = (
$a + 1) % 256;
1140 $j = ($j + $box[
$a]) % 256;
1142 $box[
$a] = $box[$j];
1144 $k = $box[(($box[
$a] + $box[$j]) % 256)];
1145 $cipherby = ord(mb_substr(
$data,
$i, 1)) ^
$k;
1146 $cipher .= chr($cipherby);
1151 $res_data = urldecode(urlencode($cipher));
1155 $res_data = urlencode(base64_encode($cipher));
1172 $arFields[
"ID"] = $this->Generate32RandomString();
1186 $pool = \Bitrix\Main\Application::getInstance()->getConnectionPool();
1187 $pool->useMasterOnly(
true);
1189 $arInsert =
$DB->PrepareInsert(
"b_captcha",
$arFields);
1191 $result =
$DB->Query(
"INSERT INTO b_captcha (" . $arInsert[0] .
") VALUES (" . $arInsert[1] .
")",
true);
1193 $pool->useMasterOnly(
false);
1202 function Delete($sid)
1206 if (!
$DB->Query(
"DELETE FROM b_captcha WHERE ID='" .
$DB->ForSQL($sid, 32) .
"' "))
static GetOptionString($module_id, $name, $def="", $site=false, $bExactSite=false)
static GetOptionInt($module_id, $name, $def="", $site=false)
static CurrentTimeFunction()
if(!is_array($prop["VALUES"])) $tmp
$_SERVER["DOCUMENT_ROOT"]
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
ShowImage($PICTURE_ID, $iMaxW=0, $iMaxH=0, $sParams=false, $strImageUrl="", $bPopup=false, $strPopupTitle=false, $iSizeWHTTP=0, $iSizeHHTTP=0)
randString($pass_len=10, $pass_chars=false)
__construct(?int $storeId, int $productId, string $barcode, int $userId)
if(empty($signedUserToken)) $key
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"