All Projects → Meteo-Concept → hcaptcha-bundle

Meteo-Concept / hcaptcha-bundle

Licence: other
A Symfony 4+ bundle to bring hCaptcha into your forms

Programming Languages

PHP
23972 projects - #3 most used programming language
Twig
543 projects

Projects that are alternatives of or similar to hcaptcha-bundle

2captcha-python
Python 3 package for easy integration with the API of 2captcha captcha solving service to bypass recaptcha, hcaptcha, funcaptcha, geetest and solve any other captchas.
Stars: ✭ 140 (+833.33%)
Mutual labels:  captcha, hcaptcha
hcaptcha-solver-python-selenium
hCaptcha solver and bypasser for Python Selenium. Simple website to try to solve hCaptcha.
Stars: ✭ 32 (+113.33%)
Mutual labels:  captcha, hcaptcha
2captcha-go
Golang Module for easy integration with the API of 2captcha captcha solving service to bypass recaptcha, hcaptcha, funcaptcha, geetest and solve any other captchas.
Stars: ✭ 31 (+106.67%)
Mutual labels:  captcha, hcaptcha
2captcha-php
PHP package for easy integration with the API of 2captcha captcha solving service to bypass recaptcha, hcaptcha, funcaptcha, geetest and solve any other captchas.
Stars: ✭ 25 (+66.67%)
Mutual labels:  captcha, hcaptcha
react-hcaptcha
hCaptcha Component Library for ReactJS
Stars: ✭ 169 (+1026.67%)
Mutual labels:  captcha, hcaptcha
dcat-auth-captcha
Sliding captcha for dcat-admin auth / dcat-admin登陆 滑动验证插件 多平台支持
Stars: ✭ 38 (+153.33%)
Mutual labels:  captcha, hcaptcha
Beelabrecaptcha2bundle
💻 Symfony bundle for Google Recaptcha2
Stars: ✭ 47 (+213.33%)
Mutual labels:  symfony-bundle, captcha
Captcha-Tools
All-in-one Python (And now Go!) module to help solve captchas with Capmonster, 2captcha and Anticaptcha API's!
Stars: ✭ 23 (+53.33%)
Mutual labels:  captcha, hcaptcha
cart
Simple Symfony 4 shopping cart application. App boilerplate
Stars: ✭ 18 (+20%)
Mutual labels:  symfony-flex
go-captcha
Go Captcha is a behavioral captcha, which implements the generation of random verification text and the verification of click position information.
Stars: ✭ 86 (+473.33%)
Mutual labels:  captcha
LexikCronFileGeneratorBundle
This symfony bundle provides service for generate cron file
Stars: ✭ 20 (+33.33%)
Mutual labels:  symfony-bundle
docusign-bundle
Symfony bundle to create electronic signatures with DocuSign
Stars: ✭ 27 (+80%)
Mutual labels:  symfony-bundle
LolautruchePaylineBundle
Symfony integration for Payline payment system
Stars: ✭ 15 (+0%)
Mutual labels:  symfony-bundle
imagetyperz-api-python3
imagetyperz-api-python3 - is a super easy to use bypass captcha API wrapper for imagetyperz.com captcha service
Stars: ✭ 25 (+66.67%)
Mutual labels:  captcha
eav-bundle
A Symfony bundle for basic EAV management
Stars: ✭ 19 (+26.67%)
Mutual labels:  symfony-bundle
eros-plugin-ios-TencentCaptcha
腾讯防水墙、滑动验证、类似bilibili滑动验证码
Stars: ✭ 21 (+40%)
Mutual labels:  captcha
DunglasTorControlBundle
Integration of PHP TorControl library in Symfony
Stars: ✭ 13 (-13.33%)
Mutual labels:  symfony-bundle
ParamConverterBundle
This bundle provides additional param converters for Symfony.
Stars: ✭ 16 (+6.67%)
Mutual labels:  symfony-bundle
Z-Spider
一些爬虫开发的技巧和案例
Stars: ✭ 33 (+120%)
Mutual labels:  captcha
AutoFormBundle
Automate Symfony form building
Stars: ✭ 68 (+353.33%)
Mutual labels:  symfony-bundle

HCaptcha bundle for Symfony 3+ Build Status v2 Build Status v3

This bundle brings into your Symfony website a new Form type, namely HCaptchaType, that is used to display and validate a CAPTCHA served by https://www.hcaptcha.com.

This bundle is tested for Symfony major versions 3, 4, 5 and 6. Major version 2 works for Symfony 3 and 4, with PHP 7.2+ ; major version 3 for Symfony 5 and 6 with PHP 7.4 or 8.x. The test dependencies requirements can be more stringent.

Installation

Applications that use Symfony Flex

Open a command console, enter your project directory and execute:

$ composer require meteo-concept/hcaptcha-bundle

In order to avoid making you install another HTTP client if you already have a compatible one, this bundle depends on virtual packages, namely PSR-18 psr/http-client-interface and PSR-17 psr/http-factory-interface. If you don't have any real package already installed in your application providing an implementation for these, composer will complain that the bundle is not installable. In this case, you have to provide a real implementation at the same time as the bundle.

For instance, for Symfony 4, 5, and 6:

$ composer require meteo-concept/hcaptcha-bundle symfony/http-client nyholm/psr7

For Symfony 3:

$ composer require meteo-concept/hcaptcha-bundle guzzlehttp/guzzle nyholm/psr7

Applications that don't use Symfony Flex

Step 1: Download the Bundle

Install the bundle with one of the commands above. You now have to enable it and configure it without the recipe.

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the config/bundles.php file of your project:

// config/bundles.php

return [
    // ...
    MeteoConcept\HCaptchaBundle\MeteoConceptHCaptchaBundle::class => ['all' => true],
];

Configuration

This captcha is provided with a Symfony flex contrib recipe so it should come with a configuration if you have those enabled. Otherwise, you can copy the configuration from the contrib repository: https://github.com/symfony/recipes-contrib/tree/master/meteo-concept/hcaptcha-bundle.

Configure the bundle, for instance in config/packages/meteo_concept_hcaptcha.yml:

parameters:
    hcaptcha_site_key: '%env(resolve:HCAPTCHA_SITE_KEY)%'
    hcaptcha_secret: '%env(resolve:HCAPTCHA_SECRET)%'

meteo_concept_h_captcha:
  hcaptcha:
    site_key: '%hcaptcha_site_key%'
    secret: '%hcaptcha_secret%'
  validation: 'strict' # this is the default

with the corresponding change in .env:

HCAPTCHA_SITE_KEY="10000000-ffff-ffff-ffff-000000000001"
HCAPTCHA_SECRET="0x0000000000000000000000000000000000000000"

The site key and secret are the values hCaptcha gives you at https://dashboard.hcaptcha.com. The global configuration makes all captchas use the same site key by default but it's possible to change it in the definition of each form.

The values shown here are dummy values usable for integration testing (https://docs.hcaptcha.com/#integrationtest). Put the real values in .env.local (at least, the secret, the site key is public).

The validation can be set to 'strict' or 'lax'. If it's 'lax', then the CAPTCHA will be considered valid even if the hCaptcha endpoint times out or return a HTTP 500 error for instance (so as to not frustrate the users too much). If it's strict (the default), then the CAPTCHA will not be considered valid unless the endpoint returns a "success: true" answer.

Configure Twig to load the specific template for the hCaptcha widget (or provide your own).

twig:
    ...
    form_themes:
        - '@MeteoConceptHCaptcha/hcaptcha_form.html.twig'
        - ...

If you use Guzzle or another HTTP library, you may also need a configuration for that bundle and its services. For instance, for Guzzle, you probably need the following in services.yaml:

services:
    Psr\Http\Client\ClientInterface:
        class: GuzzleHttp\Client
    Psr\Http\Message\RequestFactoryInterface:
        class: Nyholm\Psr7\Factory\Psr17Factory
    Psr\Http\Message\StreamFactoryInterface:
        class: Nyholm\Psr7\Factory\Psr17Factory

Usage

Use the captcha in your forms:

<?php

namespace App\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;

use MeteoConcept\HCaptchaBundle\Form\HCaptchaType;

class ContactType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('name', TextType::class, [
                'label' => 'Name',
            ])
            ->add('email', TextType::class, [
                'label' => 'Email',
            ])
            ->add('message', TextareaType::class, [
                'label' => 'How can we help you ?',
            ])
            ->add('captcha', HCaptchaType::class, [
                'label' => 'Anti-bot test',
                // optionally: use a different site key than the default one:
                'hcaptcha_site_key' => '10000000-ffff-ffff-ffff-000000000001',
            ])
        ;
    }
}

By default, the HCaptchaFormType class validates the field against constraints NotBlank and IsValidCaptcha (a new constraint installed with this bundle whose validator makes the CAPTCHA check by calling the hCaptcha API). You can override this set of constraints by passing the constraints option to the form builder. Also, HCaptchaFormType fields are passed 'mapped' => false by default since it doesn't make much sense to persist CAPTCHA values.

Updates and breaking changes

  • In major version 2, support for PHP7.1 has been dropped and support for PHP8.0 added.
  • In major version 3:
    • support for PHP <7.4 has been dropped
    • support for Symfony <5.3 has been dropped
    • support for Symfony 6.0 will be added eventually
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].