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(11mo ago)06MITPHPPHP ^8.1CI passing

Since Apr 28Pushed 4mo 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 1mo ago

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

30

—

LowBetter than 64% of packages

Maintenance68

Regular maintenance activity

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity37

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

342d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e354fdb316da535dfa8ba2e9193a473c403b6bc6fb9170778d1dc50e304c6e9d?d=identicon)[tourze](/maintainers/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

[sylius/sylius

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

8.4k5.6M647](/packages/sylius-sylius)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M151](/packages/sulu-sulu)[simplesamlphp/simplesamlphp

A PHP implementation of a SAML 2.0 service provider and identity provider.

1.1k12.4M191](/packages/simplesamlphp-simplesamlphp)[contao/core-bundle

Contao Open Source CMS

1231.6M2.3k](/packages/contao-core-bundle)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)

PHPackages © 2026

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