-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[5.1] A simple Captcha, which not every AI can solve #42777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6546222
MathCaptcha
Fedik 0269d7c
MathCaptcha
Fedik 421c361
MathCaptcha
Fedik 3d76491
MathCaptcha
Fedik d01a081
MathCaptcha
Fedik 7d8f438
MathCaptcha
Fedik 20444d9
MathCaptcha
Fedik 153a977
Update layouts/plugins/captcha/math/mathcaptcha.php
Fedik 5e7b729
Apply suggestions from code review
Fedik a210922
MathCaptcha
Fedik b0a6f7d
MathCaptcha
Fedik b324520
MathCaptcha
Fedik 08e1ca8
Apply suggestions from code review
Fedik 60c252e
MathCaptcha
Fedik 9b38a72
Apply suggestions from code review
Fedik 4827fc3
Do not hide the label
Fedik f132c0f
Better texting
Fedik a006b7a
More secret
Fedik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
administrator/components/com_admin/sql/updates/mysql/5.1.0-2024-02-08.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `locked`, `manifest_cache`, `params`, `custom_data`, `ordering`, `state`) VALUES | ||
| (0, 'plg_captcha_math', 'plugin', 'math', 'captcha', 0, 0, 1, 0, 1, '', '{}', '', 1, 0); |
2 changes: 2 additions & 0 deletions
2
administrator/components/com_admin/sql/updates/postgresql/5.1.0-2024-02-08.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "locked", "manifest_cache", "params", "custom_data", "ordering", "state") VALUES | ||
| (0, 'plg_captcha_math', 'plugin', 'math', 'captcha', 0, 0, 1, 0, 1, '', '{}', '', 1, 0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| ; Joomla! Project | ||
| ; (C) 2024 Open Source Matters, Inc. <https://www.joomla.org> | ||
| ; License GNU General Public License version 2 or later; see LICENSE.txt | ||
| ; Note : All ini files need to be saved as UTF-8 | ||
|
|
||
| PLG_CAPTCHA_MATH="Captcha - Math" | ||
| PLG_CAPTCHA_MATH_XML_DESCRIPTION="A simple Captcha plugin that uses Math." | ||
|
|
||
| PLG_CAPTCHA_MATH_EMPTY_STORE="Captcha Math solution not found, please make sure you did not submit the same form twice." | ||
| PLG_CAPTCHA_MATH_ENTER_SOLUTION="Enter solution (all or remaining digits) for" | ||
| PLG_CAPTCHA_MATH_WRONG_SOLUTION="Incorrect math solution for the Captcha." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| ; Joomla! Project | ||
| ; (C) 2024 Open Source Matters, Inc. <https://www.joomla.org> | ||
| ; License GNU General Public License version 2 or later; see LICENSE.txt | ||
| ; Note : All ini files need to be saved as UTF-8 | ||
|
|
||
| PLG_CAPTCHA_MATH="Captcha - Math" | ||
| PLG_CAPTCHA_MATH_XML_DESCRIPTION="A simple Captcha plugin that uses Math." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @package Joomla.Plugin | ||
| * @subpackage Captcha.math | ||
| * | ||
| * @copyright (C) 2024 Open Source Matters, Inc. <https://www.joomla.org> | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
|
|
||
| defined('_JEXEC') or die; | ||
|
|
||
| use Joomla\CMS\Document\Document; | ||
| use Joomla\CMS\Language\Text; | ||
| use Joomla\CMS\Layout\FileLayout; | ||
|
|
||
| extract($displayData); | ||
|
|
||
| /** | ||
| * Layout variables | ||
| * ----------------- | ||
| * @var string $name Name of the input field. | ||
| * @var array $attributes List of input attributes | ||
| * @var string $formula Formula | ||
| * @var integer $inputIdx Active Input index | ||
| * @var Document $document Document instance | ||
| * @var FileLayout $this Context | ||
| */ | ||
|
|
||
| $id = $attributes['id'] ?? ''; | ||
| $class = str_replace(' required', '', ($attributes['class'] ?? '')); | ||
|
|
||
| $letters = 'abcdefghijklmnopqrstuvwxyz'; | ||
| $classes = [ | ||
| substr(str_shuffle($letters), 0, 2) . bin2hex(random_bytes(rand(2, 7))), | ||
| substr(str_shuffle($letters), 0, 2) . bin2hex(random_bytes(rand(2, 7))), | ||
| substr(str_shuffle($letters), 0, 2) . bin2hex(random_bytes(rand(2, 7))), | ||
| ]; | ||
|
|
||
| $styles = ''; | ||
| foreach ($classes as $i => $c) { | ||
| $styles .= '.' . $c . '{display:' . ($i !== $inputIdx ? 'none' : 'block') . '}'; | ||
| } | ||
|
|
||
| $document->getWebAssetManager()->addInlineStyle($styles, ['name' => 'inline.plg_captcha_math']) | ||
| ?> | ||
| <div class="input-group mb-3"> | ||
| <span class="input-group-text"><?php echo Text::_('PLG_CAPTCHA_MATH_ENTER_SOLUTION') ?> <?php echo $this->escape($formula); ?></span> | ||
| <input type="text" value="" size="4" name="<?php echo $name; ?>[]" id="<?php echo $id; ?>" class="form-control <?php echo $classes[0] . ' ' . $class; ?>"/> | ||
| <input type="text" value="" size="4" name="<?php echo $name; ?>[]" id="<?php echo $id; ?>1" class="form-control <?php echo $classes[1] . ' ' . $class; ?>"/> | ||
| <input type="text" value="" size="4" name="<?php echo $name; ?>[]" id="<?php echo $id; ?>2" class="form-control <?php echo $classes[2] . ' ' . $class; ?>"/> | ||
| </div> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <extension type="plugin" group="captcha" method="upgrade"> | ||
| <name>PLG_CAPTCHA_MATH</name> | ||
| <version>5.1.0</version> | ||
| <creationDate>2024-02</creationDate> | ||
| <author>Joomla! Project</author> | ||
| <authorEmail>[email protected]</authorEmail> | ||
| <authorUrl>www.joomla.org</authorUrl> | ||
| <copyright>(C) 2024 Open Source Matters, Inc.</copyright> | ||
| <license>GNU General Public License version 2 or later; see LICENSE.txt</license> | ||
| <description>PLG_CAPTCHA_MATH_XML_DESCRIPTION</description> | ||
| <namespace path="src">Joomla\Plugin\Captcha\Math</namespace> | ||
| <files> | ||
| <folder plugin="math">services</folder> | ||
| <folder>src</folder> | ||
| </files> | ||
| <languages> | ||
| <language tag="en-GB">language/en-GB/plg_captcha_math.ini</language> | ||
| <language tag="en-GB">language/en-GB/plg_captcha_math.sys.ini</language> | ||
| </languages> | ||
| <config/> | ||
| </extension> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @package Joomla.Plugin | ||
| * @subpackage Captcha.math | ||
| * | ||
| * @copyright (C) 2024 Open Source Matters, Inc. <https://www.joomla.org> | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
|
|
||
| \defined('_JEXEC') or die; | ||
|
|
||
| use Joomla\CMS\Extension\PluginInterface; | ||
| use Joomla\CMS\Factory; | ||
| use Joomla\CMS\Plugin\PluginHelper; | ||
| use Joomla\DI\Container; | ||
| use Joomla\DI\ServiceProviderInterface; | ||
| use Joomla\Event\DispatcherInterface; | ||
| use Joomla\Plugin\Captcha\Math\Extension\Math; | ||
|
|
||
| return new class () implements ServiceProviderInterface { | ||
| /** | ||
| * Registers the service provider with a DI container. | ||
| * | ||
| * @param Container $container The DI container. | ||
| * | ||
| * @return void | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public function register(Container $container) | ||
| { | ||
| $container->set( | ||
| PluginInterface::class, | ||
| function (Container $container) { | ||
| $plugin = new Math( | ||
| $container->get(DispatcherInterface::class), | ||
| (array) PluginHelper::getPlugin('captcha', 'math') | ||
| ); | ||
| $plugin->setApplication(Factory::getApplication()); | ||
|
|
||
| return $plugin; | ||
| } | ||
| ); | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @package Joomla.Plugin | ||
| * @subpackage Captcha.math | ||
| * | ||
| * @copyright (C) 2024 Open Source Matters, Inc. <https://www.joomla.org> | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
|
|
||
| namespace Joomla\Plugin\Captcha\Math\Extension; | ||
|
|
||
| use Joomla\CMS\Event\Captcha\CaptchaSetupEvent; | ||
| use Joomla\CMS\Plugin\CMSPlugin; | ||
| use Joomla\Event\SubscriberInterface; | ||
| use Joomla\Plugin\Captcha\Math\Provider\MathCaptchaProvider; | ||
|
|
||
| // phpcs:disable PSR1.Files.SideEffects | ||
| \defined('_JEXEC') or die; | ||
| // phpcs:enable PSR1.Files.SideEffects | ||
|
|
||
| /** | ||
| * Math captcha Plugin | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| final class Math extends CMSPlugin implements SubscriberInterface | ||
| { | ||
| /** | ||
| * Returns an array of events this plugin will listen to. | ||
| * | ||
| * @return array | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public static function getSubscribedEvents(): array | ||
| { | ||
| return [ | ||
| 'onCaptchaSetup' => 'onCaptchaSetup', | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * Register Captcha instance | ||
| * | ||
| * @param CaptchaSetupEvent $event | ||
| * | ||
| * @return void | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public function onCaptchaSetup(CaptchaSetupEvent $event) | ||
| { | ||
| $this->loadLanguage(); | ||
| $event->getCaptchaRegistry()->add(new MathCaptchaProvider($this->getApplication())); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.