PHPackages                             tourze/captcha-challenge-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. tourze/captcha-challenge-bundle

ActiveSymfony-bundle[Validation &amp; Sanitization](/categories/validation)

tourze/captcha-challenge-bundle
===============================

Symfony图片验证码验证模块

0.0.3(1y ago)06MITPHPPHP ^8.1CI passing

Since Apr 28Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/tourze/captcha-challenge-bundle)[ Packagist](https://packagist.org/packages/tourze/captcha-challenge-bundle)[ RSS](/packages/tourze-captcha-challenge-bundle/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (18)Versions (4)Used By (0)

Captcha Challenge Bundle
========================

[](#captcha-challenge-bundle)

[![PHP Version](https://camo.githubusercontent.com/7663c9d53dc13cedaf0660a8745a7e77d2dd711257f36aa86ebce12a0600ef42/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e312d626c75652e737667)](https://www.php.net/)[![License](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](LICENSE)[![Build Status](https://camo.githubusercontent.com/c27a457659b89ee4f1f80f7995c559dd37f2051bde7167ad25791e5c5c92cc8e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6275696c642d70617373696e672d627269676874677265656e2e737667)](#)[![Coverage](https://camo.githubusercontent.com/b3545ae1bcdb4ea486f71f87b43001e82dd21933bc8035d44601706c851265da/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d627269676874677265656e2e737667)](#)

[English](README.md) | [中文](README.zh-CN.md)

A Symfony Bundle that provides image captcha functionality for website security protection.

Features
--------

[](#features)

- Generate random captcha codes and store challenge values in cache
- Provide image captcha generation and display
- Provide captcha verification and one-time consumption functionality
- Support JSON-RPC interface

Installation
------------

[](#installation)

Install via Composer:

```
composer require tourze/captcha-challenge-bundle
```

Configuration
-------------

[](#configuration)

Register the Bundle in your Symfony application:

```
// config/bundles.php
return [
    // ...
    Tourze\CaptchaChallengeBundle\CaptchaChallengeBundle::class => ['all' => true],
];
```

Ensure environment variables are configured:

```
# .env
LOGIN_CHALLENGE_TYPE=captcha # Enable captcha functionality, set to 'null' to disable
```

Usage
-----

[](#usage)

### Generating Captcha and Getting Image

[](#generating-captcha-and-getting-image)

```
// In your controller
use Tourze\CaptchaChallengeBundle\Service\ChallengeService;

class YourController extends AbstractController
{
    public function generateCaptcha(ChallengeService $challengeService): Response
    {
        // Generate captcha
        $challengeKey = $challengeService->generateChallenge();

        // Get captcha image URL
        $imageUrl = $challengeService->generateChallengeCaptchaImageUrl($challengeKey);

        return $this->json([
            'challengeKey' => $challengeKey,
            'imageUrl' => $imageUrl,
        ]);
    }
}
```

### Verifying User Input Captcha

[](#verifying-user-input-captcha)

```
// In your controller
use Tourze\CaptchaChallengeBundle\Service\ChallengeService;

class YourController extends AbstractController
{
    public function verifyCode(
        Request $request,
        ChallengeService $challengeService
    ): Response
    {
        $challengeKey = $request->request->get('challengeKey');
        $userInput = $request->request->get('captchaCode');

        // Verify and consume captcha
        $isValid = $challengeService->checkAndConsume($challengeKey, $userInput);

        if (!$isValid) {
            return $this->json(['success' => false, 'message' => 'Invalid captcha code']);
        }

        return $this->json(['success' => true]);
    }
}
```

Advanced Usage
--------------

[](#advanced-usage)

### Custom Captcha Configuration

[](#custom-captcha-configuration)

```
// Custom captcha generation with specific settings
$challengeKey = $challengeService->generateChallenge();

// Generate image with custom parameters
$imageUrl = $challengeService->generateChallengeCaptchaImageUrl($challengeKey);
```

### Integration with Forms

[](#integration-with-forms)

```
// In your form type
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;

$builder
    ->add('challengeKey', HiddenType::class)
    ->add('captchaCode', TextType::class, [
        'label' => 'Enter captcha code',
        'required' => true,
    ]);
```

Technical Details
-----------------

[](#technical-details)

- Captcha uses 5-digit random numbers
- Captcha is stored in cache for 5 minutes
- After successful verification, it is immediately deleted from cache to prevent reuse
- Uses GD library to generate images, supports anti-OCR functionality

Requirements
------------

[](#requirements)

- PHP 8.1+
- GD extension
- Symfony 6.4 framework
- PSR-16 cache implementation
- Gregwar/Captcha library

License
-------

[](#license)

This Bundle is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance58

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~17 days

Total

3

Last Release

398d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/13899502?v=4)[tourze](/maintainers/tourze)[@tourze](https://github.com/tourze)

---

Top Contributors

[![tourze](https://avatars.githubusercontent.com/u/13899502?v=4)](https://github.com/tourze "tourze (3 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-captcha-challenge-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-captcha-challenge-bundle/health.svg)](https://phpackages.com/packages/tourze-captcha-challenge-bundle)
```

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.9M387](/packages/easycorp-easyadmin-bundle)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M574](/packages/shopware-core)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

9421.6k61](/packages/open-dxp-opendxp)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.9M738](/packages/sylius-sylius)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

85036.3k](/packages/flow-php-flow)[pimcore/pimcore

Content &amp; Product Management Framework (CMS/PIM/E-Commerce)

3.8k3.8M508](/packages/pimcore-pimcore)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
