This commit is contained in:
Roman Kelesidis 2025-03-08 19:51:04 +03:00
commit e171443d80
2 changed files with 8 additions and 1 deletions

View file

@ -2070,6 +2070,7 @@ function bb_captcha(string $mode): bool|string
'hCaptcha' => \TorrentPier\Captcha\HCaptcha::class, 'hCaptcha' => \TorrentPier\Captcha\HCaptcha::class,
'yandex' => \TorrentPier\Captcha\YandexSmartCaptcha::class, 'yandex' => \TorrentPier\Captcha\YandexSmartCaptcha::class,
'cloudflare' => \TorrentPier\Captcha\CloudflareTurnstileCaptcha::class, 'cloudflare' => \TorrentPier\Captcha\CloudflareTurnstileCaptcha::class,
'text' => \TorrentPier\Captcha\TextCaptcha::class
]; ];
if (!isset($captchaClasses[$settings['service']])) { if (!isset($captchaClasses[$settings['service']])) {
bb_die(sprintf('Captcha service (%s) not supported', $settings['service'])); bb_die(sprintf('Captcha service (%s) not supported', $settings['service']));

View file

@ -10,6 +10,7 @@
namespace TorrentPier\Captcha; namespace TorrentPier\Captcha;
use Gregwar\Captcha\CaptchaBuilder; use Gregwar\Captcha\CaptchaBuilder;
use Gregwar\Captcha\PhraseBuilder;
/** /**
* Class TextCaptcha * Class TextCaptcha
@ -33,6 +34,8 @@ class TextCaptcha implements CaptchaInterface
*/ */
public function __construct(array $settings) public function __construct(array $settings)
{ {
session_start();
$this->settings = $settings; $this->settings = $settings;
$this->captcha = new CaptchaBuilder; $this->captcha = new CaptchaBuilder;
} }
@ -44,8 +47,10 @@ class TextCaptcha implements CaptchaInterface
*/ */
public function get(): string public function get(): string
{ {
$this->captcha->build();
return " return "
<img src=" . $builder->inline() . " /> <img src=" . $this->captcha->inline() . " />
<input type='text' name='captcha_phrase' />
"; ";
} }
@ -56,5 +61,6 @@ class TextCaptcha implements CaptchaInterface
*/ */
public function check(): bool public function check(): bool
{ {
return (isset($_SESSION['phrase']) && PhraseBuilder::comparePhrases($_SESSION['phrase'], $_POST['captcha_phrase']));
} }
} }