[+] Добавлена поддержка каптчи
[-] выпилено тестовое
This commit is contained in:
1 parent
27df856ab6
commit
0479d29b08
6 files changed
+96
-262
No files matched your search
+1
-2
@@ -24,5 +24,4 @@
|
||||
|
||||
require_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
$_SESSION['captchaCode'] = SystemFunctions::generateCode(8, 8);
|
||||
SystemFunctions::showCaptcha($_SESSION['captchaCode']);
|
||||
SystemFunctions::showCaptcha();
|
||||
@@ -208,3 +208,10 @@
|
||||
if (!defined('SERVER_EMAIL_NAME')) {
|
||||
define('SERVER_EMAIL_NAME', 'Delta Framework');
|
||||
}
|
||||
|
||||
/**
|
||||
* Флаг использования Captcha
|
||||
*/
|
||||
if (!defined('USE_CAPTCHA')) {
|
||||
define('USE_CAPTCHA', true);
|
||||
}
|
||||
@@ -975,7 +975,7 @@
|
||||
*/
|
||||
public static function generateCode(int $min = 4, int $max = 8): string
|
||||
{
|
||||
$chars = 'ABCDEFGHJKLMNPRSTUVXYZ23456789';
|
||||
$chars = 'ABCDEFGHJKLMNPRSTVXYZ23456789';
|
||||
$length = rand($min, $max);
|
||||
$numChars = strlen($chars);
|
||||
$str = '';
|
||||
@@ -994,12 +994,17 @@
|
||||
/**
|
||||
* Генерация и отображение картинки-каптчи
|
||||
*
|
||||
* @param string $code Код
|
||||
* @param string|null $code Код
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function showCaptcha(string $code = 'test'): void
|
||||
public static function showCaptcha(?string $code = null): void
|
||||
{
|
||||
if ($code === null) {
|
||||
$code = self::generateCode(8, 8);
|
||||
$_SESSION['captchaCode'] = $code;
|
||||
}
|
||||
|
||||
$width = 80;
|
||||
$height = 30;
|
||||
$img = imagecreate($width, $height);
|
||||
@@ -1010,7 +1015,7 @@
|
||||
// Задаем цвета
|
||||
$lineColor = imagecolorallocate($img, 150, 150, 150);
|
||||
$pixelColor = imagecolorallocate($img, 150, 150, 150);
|
||||
$whiteColor = imagecolorallocate($img, 255, 255, 255);
|
||||
$whiteColor = imagecolorallocate($img, 180, 255, 180);
|
||||
$blackColor = imagecolorallocate($img, 0, 0, 0);
|
||||
|
||||
// Рисуем линии 1
|
||||
@@ -1054,4 +1059,16 @@
|
||||
|
||||
imagepng($img);
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверка кода каптчи
|
||||
*
|
||||
* @param int $code Код
|
||||
*
|
||||
* @return bool Результат валидации
|
||||
*/
|
||||
public static function isValidCaptcha(string $code): bool
|
||||
{
|
||||
return (string)$_SESSION['captchaCode'] === $code;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user