Search by

switon / captcha

switon

Sessionless image CAPTCHA challenges with shared-store verification for Switon Framework

v1.0.0 2026-06-06 13:43 UTC

This package is auto-updated.

Last update: 2026-09-07 05:53:27 UTC


README

CI PHP 8.3+

Switon's CAPTCHA challenge, proof, and action-guard layer.

Highlights

  • Challenge and verification flow: generate a CAPTCHA, then verify the returned proof.
  • Standard request fields: CaptchaProofResolver reads the usual CAPTCHA key and code fields.
  • Protected actions: #[CaptchaRequired] blocks an action until proof is valid.
  • Image backends: the package includes GD and Imagick adapters for image generation.
  • Observable checks: creation, verification, and failure activity can be observed.

Installation

composer require switon/captcha

Quick Start

use Switon\Captcha\CaptchaInterface;
use Switon\Captcha\Attribute\CaptchaRequired;
use Switon\Captcha\CaptchaProof;
use Switon\Core\Attribute\Autowired;

class LoginController
{
    #[Autowired] protected CaptchaInterface $captcha;

    public function getCaptcha(): array
    {
        return $this->captcha->create();
    }

    public function verifyAction(CaptchaProof $proof): void
    {
        $this->captcha->verify($proof);
    }

    #[CaptchaRequired]
    public function submitAction(): void
    {
    }
}

Docs: https://docs.switon.dev/latest/captcha

License

MIT.