- md5
- a489de946bc0a69480e78e542d99a291
- sha1
- 0451f0c4e47a84856d4ca2f808495c88ecd5055e
- sha256
- e603b1f8a1ebb43af68b207aaee392ab6f641439b68cba560646f94ee62f77f9
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
<?php
/**
* @package Joomla.Plugin
* @subpackage Captcha.POWCaptcha
*
* @copyright (C) 2025 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\Captcha\POWCaptcha\Extension;
use Joomla\CMS\Event\Captcha\CaptchaSetupEvent;
use Joomla\CMS\Event\Plugin\AjaxEvent;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Session\Session;
use Joomla\Event\SubscriberInterface;
use Joomla\Plugin\Captcha\POWCaptcha\Provider\POWCaptchaProvider;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Proof of work captcha Plugin
* Based on the ALTCHA captcha library
*
* @since 6.1.0
*/
final class POWCaptcha extends CMSPlugin implements SubscriberInterface
{
/**
* Load the language file on instantiation.
*
* @var boolean
* @since 6.1.0
*/
protected $autoloadLanguage = true;
public static function getSubscribedEvents(): array
{
return [
'onAjaxPowcaptcha' => 'handleAjaxRequest',
'onCaptchaSetup' => 'setupCaptcha',
];
}
/**
* Register Captcha instance
*
* @param CaptchaSetupEvent $event
*
* @return void
*/
public function setupCaptcha(CaptchaSetupEvent $event)
{
$event->getCaptchaRegistry()->add($this->getProvider());
}
/**
* Handles the ajax request triggered by altcha to fetch the challenge code
*
* @param AjaxEvent $event
*/
public function handleAjaxRequest(AjaxEvent $event)
{
// CRSF Token check
if (!Session::checkToken('get')) {
$event->updateEventResult(json_encode([]));
return;
}
$event->updateEventResult(
json_encode(
$this->getProvider()->getChallenge()
)
);
}
/**
* Returns the actual captcha provider instance
*
* @return POWCaptchaProvider
*/
protected function getProvider(): POWCaptchaProvider
{
return new POWCaptchaProvider(
$this->params,
$this->getApplication()
);
}
}
The same content is in 23 releases, Joomla 6.1.0-alpha2 to 6.2.0-beta2. See them all, or every version of this file.