:passport_control: Helper for Google's new noCAPTCHA (reCAPTCHA v2 & v3)

Overview

noCAPTCHA (new reCAPTCHA) Packagist License For PHP

Github Workflow Status Coverage Status Scrutinizer Code Quality SensioLabs Insight Github Issues

Packagist Packagist Release Packagist Downloads

By ARCANEDEV©

What is reCAPTCHA?

reCAPTCHA is a free service that protects your site from spam and abuse. It uses advanced risk analysis engine to tell humans and bots apart. With the new API, a significant number of your valid human users will pass the reCAPTCHA challenge without having to solve a CAPTCHA. reCAPTCHA comes in the form of a widget that you can easily add to your blog, forum, registration form, etc.

New Google reCAPTCHA

Features

  • Framework agnostic package.
  • v2 (+ Invisible) & v3 reCaptcha are supported.
  • Easy setup & configuration.
  • Well documented & IDE Friendly.
  • Well tested with maximum code quality.
  • Laravel 4.2 to 8.x are supported.
  • PSR-7 Support (ServerRequest verification).
  • Made with ❤️ & .

Table of contents

  1. Installation and Setup
  2. Configuration
  3. Usage
  4. Extras
  5. FAQ

Contribution

Any ideas are welcome. Feel free to submit any issues or pull requests, please check the contribution guidelines.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

Comments
  • Don't validate captcha in testing environment

    Don't validate captcha in testing environment

    Hi,

    This isn't really an issue, just a suggestion in case anyone cares :)

    I'm trying to test my code with Laravel's handy helpers and MailThief for intercepting e-mails... But getting past the captcha with an automated script is obviously not so easy...

    To get around this, I read that some people just disable the captcha for testing. So to do this, I copied your validator and changed it like this:

        Validator::extend('nocaptcha', function($attribute, $value, $parameters, $validator) {
            unset($attribute);
    
            if (app()->environment('testing')) {
                return true;
            }
    
            return app('arcanedev.no-captcha')->verify($value, request()->getClientIp());
        });
    

    So basically, I just check if the environment is set to testing, which is the default for Laravel, and if so I always let it pass.

    I don't know if this is something you would want to include in your package, perhaps with configurable environments that should be skipped or something...

    enhancement tests 
    opened by ivanvermeyen 17
  • Trouble with Form macro in Laravel 5.5

    Trouble with Form macro in Laravel 5.5

    • noCaptcha Version: 5.0
    • Laravel Version: 5.5.3
    • PHP Version: 7.1

    Description:

    Trying to use Form::captcha() with error.

    Steps To Reproduce:

    Set up captcha with Form::captcha() instead of Captcha::display()


    I have this in one other Laravel 5.4 projects without issue.

    The problem lies in Arcanedev\NoCaptcha\NoCaptchaServiceProvider

    Trying to import Arcanedev\LaravelHtml\Contracts\FormBuilder and not being able to find it.

    Also, using Captcha::display() doesn't break the page, but it also doesn't display the actual captcha, though the div does exist.

    need help laravel 
    opened by rappasoft 11
  • Multiple noCaptcha

    Multiple noCaptcha

    Hello,

    Firstly thanks for the plugin...

    I am trying to add multiple captchas on a single page with laravel 4.2 using:

     public function scriptWithCallback(array $captchas, $callbackName = 'captchaRenderCallback')
    

    It does work but i need to refresh/reload the page for the captchas to render/appear in the page... I tried grepcaptcha.reset(); with no luck...

    Any ideas on how to deal with this? Thank you

    bug fixed 
    opened by pns2050 10
  • How to reset multiple captchas?

    How to reset multiple captchas?

    Hi! How can I reset captcha by opt_widget_id (as they say on google captcha docs)?

    When I try to reset captcha by attribute 'id' in div with 'g-recaptcha' class, it does not work. On StackOverflow there is a answer with that solution:

    var widgetId = grecaptcha.render(container);
    grecaptcha.reset(widgetId);
    

    but in \Arcanedev\NoCaptcha\NoCaptcha::renderCaptchas function you do render captchas without saving widget ID to anywhere

    return implode(PHP_EOL, array_map(function($captcha) {
        return "if (document.getElementById('$captcha')) { grecaptcha.render('$captcha', {'sitekey' : '{$this->siteKey}'}); }";
    }, $captchas));
    

    Maybe there is some function to get widgetID?

    feature request 
    opened by madaolex 6
  • Fails to display google images

    Fails to display google images

    Clicking on the "I'm not a robot" button causes the "waiting" cursor to appear, but nothing else happens. This is after following the installation instructions for a Laravel 5.2 application.

    opened by DA40 5
  • No scriptWithCallback() output in Laravel 5.2

    No scriptWithCallback() output in Laravel 5.2

    Hi,

    I'm a bit clueless about this one... I have a page (Laravel 5.2 blade file) with 2 forms. Each form successfully renders a captcha div:

    {!! Captcha::display('captcha1', ['data-theme' => 'dark']) !!}
    {!! Captcha::display('captcha2', ['data-theme' => 'dark']) !!}
    

    This results in:

    <div class="g-recaptcha" data-sitekey="XXXX" id="captcha1" name="captcha1" data-theme="dark"></div>
    

    But at the bottom of the page, the script doesn't get echo'd out:

    {!! Captcha::scriptWithCallback(['captcha1', 'captcha2']) !!}
    

    However, when I call this method with php artisan tinker, I do get the following output:

    >>> Captcha::scriptWithCallback(['captcha1', 'captcha2']);
    => """
       <script>\n
       var captchaRenderCallback = function() {\n
       if (document.getElementById('captcha1')) { grecaptcha.render('captcha1', {'sitekey' : 'XXXX'}); }\n
       if (document.getElementById('captcha2')) { grecaptcha.render('captcha2', {'sitekey' : 'XXXX'}); }\n
       };\n
       </script>\n
       <script src="https://www.google.com/recaptcha/api.js?hl=nl&onload=captchaRenderCallback&render=explicit" async defer></script>
       """
    >>>
    

    If I paste this script on the page, the captchas work (although they don't have the dark theme).

    Do you have any ideas why I'm not getting any output?

    need help 
    opened by ivanvermeyen 5
  • Interface 'Illuminate\Contracts\Validation\Rule' not found

    Interface 'Illuminate\Contracts\Validation\Rule' not found

    • noCaptcha Version: ^5.0
    • Laravel Version: 5.4.35
    • PHP Version: 7.0.22

    Description:

    Error on validation Interface 'Illuminate\Contracts\Validation\Rule' not found - in CaptchaRule.php (line 12)

    Steps To Reproduce:

    Create a validatorRequest File in request directory and use the following rule : use Arcanedev\NoCaptcha\Rules\CaptchaRule;

    public function rules()
    {
        $rules = [
            'name' => 'required',
            'email' => 'required|email',
            'message' => 'required',
            'g-recaptcha-response' => ['required', new CaptchaRule],
        ];
    
        return $rules;
    }
    

    Processing :

    public function sendmail(ValidatorRequest $request)
    {
        $data = $request->all();
        dd($data);
    }
    
    duplicate need help laravel 
    opened by visualight 4
  • Your requirements could not be resolved to an installable set of packages.

    Your requirements could not be resolved to an installable set of packages.

    Problem 1 - Installation request for arcanedev/no-captcha ^10.1 -> satisfiable by arcanedev/no-captcha[10.1.0]. - Conclusion: remove laravel/framework v5.7.28 - Conclusion: don't install laravel/framework v5.7.28 - arcanedev/no-captcha 10.1.0 requires arcanedev/support ^5.0 -> satisfiable by arcanedev/support[5.0.0, 5.1.0, 5.1.1]. - arcanedev/support 5.1.0 requires illuminate/support ^6.0 -> satisfiable by laravel/framework[6.x-dev], illuminate/support[6.x-dev, v6.0.0, v6.0.1, v6.0.2, v6.0.3, v6.0.4, v6.1.0, v6.2.0, v6.3.0, v6.4.1, v6.5.0, v6.5.1, v6.5.2, v6.6.0]. - arcanedev/support 5.1.1 requires illuminate/support ^6.0 -> satisfiable by laravel/framework[6.x-dev], illuminate/support[6.x-dev, v6.0.0, v6.0.1, v6.0.2, v6.0.3, v6.0.4, v6.1.0, v6.2.0, v6.3.0, v6.4.1, v6.5.0, v6.5.1, v6.5.2, v6.6.0]. - arcanedev/support 5.0.0 requires illuminate/filesystem ~6.0.0 -> satisfiable by illuminate/filesystem[v6.0.0, v6.0.1, v6.0.2, v6.0.3, v6.0.4]. - Can only install one of: laravel/framework[6.x-dev, v5.7.28]. - don't install illuminate/support 6.x-dev|don't install laravel/framework v5.7.28 - don't install illuminate/support v6.0.0|don't install laravel/framework v5.7.28 - don't install illuminate/support v6.0.1|don't install laravel/framework v5.7.28 - don't install illuminate/support v6.0.2|don't install laravel/framework v5.7.28 - don't install illuminate/support v6.0.3|don't install laravel/framework v5.7.28 - don't install illuminate/support v6.0.4|don't install laravel/framework v5.7.28 - don't install illuminate/support v6.1.0|don't install laravel/framework v5.7.28 - don't install illuminate/support v6.2.0|don't install laravel/framework v5.7.28 - don't install illuminate/support v6.3.0|don't install laravel/framework v5.7.28 - don't install illuminate/support v6.4.1|don't install laravel/framework v5.7.28 - don't install illuminate/support v6.5.0|don't install laravel/framework v5.7.28 - don't install illuminate/support v6.5.1|don't install laravel/framework v5.7.28 - don't install illuminate/support v6.5.2|don't install laravel/framework v5.7.28 - don't install illuminate/support v6.6.0|don't install laravel/framework v5.7.28 - don't install illuminate/filesystem v6.0.0|don't install laravel/framework v5.7.28 - don't install illuminate/filesystem v6.0.1|don't install laravel/framework v5.7.28 - don't install illuminate/filesystem v6.0.2|don't install laravel/framework v5.7.28 - don't install illuminate/filesystem v6.0.3|don't install laravel/framework v5.7.28 - don't install illuminate/filesystem v6.0.4|don't install laravel/framework v5.7.28 - Installation request for laravel/framework == 5.7.28.0 -> satisfiable by laravel/framework[v5.7.28].

    duplicate 
    opened by KumaChenGC 2
  • "Class 'Captcha' not found" AND "Call to undefined method Arcanedev\NoCaptcha\NoCaptchaV3::display()"

    • noCaptcha Version: 9.0
    • Laravel Version: 5.8
    • PHP Version: 7.3.1

    Description:

    If i use {!! Form::captcha() !!} in form i receive error Class 'Captcha' not found (View: ....) If i use {!! no_captcha()->display() !!} in form i receive error Call to undefined method Arcanedev\NoCaptcha\NoCaptchaV3::display()

    Also tried to switch from {!! Captcha::script() !!} to script()->toHtml(); ?> with same results.

    Steps To Reproduce:

    • composer install arcanedev/no-captcha
    • php artisan vendor:publish (published the Arcanedev\NoCaptcha\NoCaptchaServiceProvider )

    In Blade:

    {!! Form::open(array('class'=>'form contact-form', 'id'=>'contact-form')) !!}
    [...]
    {!! Form::captcha() !!} OR {!! no_captcha()->display() !!}
    [...]
    {!! Form::close() !!}
    
    
    @push('scripts')
    [...]
    {!! Captcha::script() !!} OR {!! no_captcha()->display() !!}
    [...]
    @endpush
    

    In Controller:

    use Arcanedev\NoCaptcha\Rules\CaptchaRule;
    [...]
            $this->validate($request, [
                [...]
                'g-recaptcha-response' => ['required', new CaptchaRule],
                ]);
    [...]
    {!! Form::close() !!}
    
    
    duplicate 
    opened by luigimarmo 2
  • reCAPTCHA v2 issue

    reCAPTCHA v2 issue

    • noCaptcha Version: 9.x
    • Laravel Version: 5.8.x
    • PHP Version: 7.3.x

    Description:

    The field validation keeps giving the error If you read this message, then you're a robot..

    I have the validation like in the docs: 'g-recaptcha-response' => ['required', new CaptchaRule],

    I add some ips to try and skip it, but it is not working too. I have them in the cfg like this:

    'skip-ips' => [
        'localhost',
        '127.0.0.1',
        '192.168.10.10'
    ],
    

    Any ideas of what might be the issue? Thanks.

    need help 
    opened by Morinohtar 2
  • Problem with using V2 driver

    Problem with using V2 driver

    • noCaptcha Version: 8.0.2
    • Laravel Version: 5.7.24
    • PHP Version: 7.1.22

    Description:

    Is it right to initialize V3 driver instead of V2 here?

    https://github.com/ARCANEDEV/noCAPTCHA/blob/cbef775f98be11199d5b953603b922db3fa3d116/src/NoCaptchaManager.php#L49-L56

    Steps To Reproduce:

    It's simple to reproduce, just use {!! no_captcha('v2')->display() !!} in blade template and you get an error that NoCapthcaV3 doesn't have display() method.

    bug laravel 
    opened by rwnet 2
  • RecaptchaV3. Error «incorrect-captcha-sol»

    RecaptchaV3. Error «incorrect-captcha-sol»

    • noCaptcha Version: 13.0.0
    • Laravel Version: 9.16.0
    • PHP Version: 8.1.5

    Description:

    When verifying the request, the error "incorrect-captcha-sol" is returned. I tried recreating recaptcha keys, different connection methods, clearing browser cookies, opening the site through a different browser.

    Steps To Reproduce:

    For example FeedbackController.php file:

    public function post(Request $request)
    {
        $captcha = new NoCaptchaV3(
            'RECAPTCHAV3_SECRET',
            'RECAPTCHAV3_SITEKEY'
        );
    
        if ($request->all() && $request['g-recaptcha-response']) {
            $response = $captcha->verify($request['g-recaptcha-response'] ?? null);
    
            if ($response->isSuccess()) {
                ...
            } else {
                dd($response);
            }
        }
    }
    

    feedback.blade.php:

    <form action="{{ route('feedback.post') }}" method="POST" name="formFeedback" class="contact-form contact__form">
        {{ csrf_field() }}
        <input type="hidden" value="{{$page}}" name="page" />
        <input class="contact-form__input" name="phone" type="text" placeholder="Телефон*">
        <input class="contact-form__input" name="name" type="text" placeholder="Имя">
        <textarea class="contact-form__input contact-form__area" name="msg" placeholder="Текст сообщения"></textarea>
        <span class="contact-form__policy">Нажимая "Отправить" вы соглашаетесь с политикой обработки персональных данных</span>
        <input class="contact-form__btn btn" type="submit" value="Отправить">
    
        {{ no_captcha()->input('g-recaptcha-response') }}
    </form>
    
    {{ no_captcha()->script() }}
    {{ no_captcha()->getApiScript() }}
    
    <script>
        grecaptcha.ready(() => {
            window.noCaptcha.render('formFeedback', (token) => {
                let recaptchaInputs = document.querySelectorAll('#g-recaptcha-response');
                recaptchaInputs.forEach(function (element) {
                    element.value = token;
                });
            });
        });
    </script>
    

    main.js:

    const recaptchaSitekey = 'RECAPTCHAV3_SITEKEY';
    
    $('.contact-form').on('submit', function(e) {
        e.preventDefault();
        var formData = $(this).serializeArray().reduce(function(obj, item) {
            obj[item.name] = item.value;
            return obj;
        }, {});
    
        let url = $(this).attr('action');
        return axios
            .post(url, formData)
            .then(function(res) {
                if(res.data.status=='ok'){
                    notifier.success('Спасибо, ваше сообщение успешно отправлено!');
    
                    grecaptcha.reset(recaptchaSitekey);
                    grecaptcha.ready(() => {
                        window.noCaptcha.render('thatForm', (token) => {
                            var recaptchaInputs = document.querySelectorAll('#g-recaptcha-response');
                            recaptchaInputs.forEach(function (element) {
                                element.value = token;
                            });
                        });
                    });
                }
                else{
                    notifier.alert('Что-то пошло не так :( Попробуйте позже...')
                }
            })
            .catch(error => {
                notifier.alert('Что-то пошло не так :( Попробуйте позже...')
    
                console.error(error);
            });
    })
    
    opened by develop2-webalt 0
  • Laravel Dusk Testing not working

    Laravel Dusk Testing not working

    • noCaptcha Version: 13.0.0
    • Laravel Version: 9.9
    • PHP Version: 8.1

    Using Vue for the form submission.

    Also left the same comment in a topic that was already closed #39

    Cant seem to make the test work with Dusk, though the Feature Test works fine. Dont think the mock is working in Dusk...

    If i log the response from the rule, it spits this:

    `{"Arcanedev\\NoCaptcha\\Utilities\\ResponseV2":{"success":false,"hostname":null,"challenge_ts":null,"apk_package_name":null,"error-codes":["invalid-input-response"]}}`
    

    So, the rule response comes as false.

    Code:

    
        protected function ignoreCaptcha(string $name = 'g-recaptcha-response'): void
        {
            NoCaptchaFacade::shouldReceive('display')
                ->andReturn('<input type="textarea"  value="anything, really" name="' . $name . '">');
                
            NoCaptchaFacade::shouldReceive('script')
                ->andReturn('<script src="captcha.js"></script>');
                
            NoCaptchaFacade::shouldReceive('verify')
                ->andReturn(NoCaptchaFacade::getFacadeRoot());
                
            NoCaptchaFacade::shouldReceive('isSuccess')
                ->andReturn(true);
        }
    
        /** @test */
        public function it_submits_contact_form()
        {
            $this->ignoreCaptcha();
    
            $this->browse(function (Browser $browser) {
                $browser->visitRoute('contact')
                    ->type('name', $this->faker->name)
                    ->type('email', $this->faker->safeEmail)
                    ->type('message', $this->faker->paragraphs(3, true))
                    ->fillHidden('g-recaptcha-response', '1')
                    ->pressAndWaitFor('Submit', 3)
                    ->assertSee('Message sent!');
            });
        }
    
    opened by Morinohtar 0
Releases(13.0.0)
Owner
ARCANEDEV
ARCANEDEV
Hcaptcha & Google ReCaptcha Solution for Laravel Framework

Laravel Captcha is a wrapper around HCaptcha & Google Recaptcha. It provides very easy-to-use Facade, Validation Rule, and blade directives.

Rahul Dey 47 Oct 27, 2022
A helper package to flash a bootstrap alert to the browser via a Facade or a helper function.

Alert Box (Laravel) A helper package to flash a bootstrap alert to the browser via a Facade or a helper function. <div class="alert alert-info fade in

Ben-Piet O'Callaghan 17 Dec 30, 2022
Cache-purge-helper - Additional instances where nginx-helper and lscache plugin should be purged.

cache-purge-helper Additional instances where nginx-helper and lscache plugin should be purged. Install Extract the zip file. Upload them to /wp-conte

Jordan 10 Oct 5, 2022
This package provides new helper functions that take care of handling all the translation hassle and do it for you.

Laravel Translate Message ?? This package provides new helper functions that take care of handling all the translation hassle and do it for you. Insta

Basel Rabia 17 Feb 8, 2022
This package adds support for verifying new email addresses: when a user updates its email address, it won't replace the old one until the new one is verified.

Laravel Verify New Email Laravel supports verifying email addresses out of the box. This package adds support for verifying new email addresses. When

Protone Media 300 Dec 30, 2022
The missing laravel helper that allows you to inspect your eloquent queries with it's bind parameters

Laravel Query Inspector The missing laravel helper that allows you to ispect your eloquent queries with it's bind parameters Motivations Let's say you

Mouad ZIANI 59 Sep 25, 2022
A collection of helper functions that I use across my projects.

A collection of helper functions that I use across my projects. This package includes some of the helper functions that I tend to use in all of my pro

Ryan Chandler 33 Oct 18, 2022
Laravel-Mix helper for projects with complex & multi assets.

Laravel-Mix helper for projects with complex & multi assets. ?? Getting started Since mix introduced in laravel 5.4 it is recommended to use this pack

Fandogh 27 Oct 4, 2022
A Laravel response helper methods.

A Laravel response helper methods. The package respond provides a fluent syntax to form array or json responses.

Najm Njeim 5 Nov 2, 2021
Laravel FullCalendar.io Helper

Laravel 5 Full Calendar Helper For Laravel 4.2: use the laravel-4 branch This is a simple helper package to make generating http://fullcalendar.io in

Shawn Tunney 616 Dec 30, 2022
`dd` is a helper method in Laravel. This package will add the `dd` to your application.

dd dd is a helper method in Laravel. This package will add the dd to your application. Install Run composer require larapack/dd 1.* For Laravel Larave

Larapack 109 Dec 26, 2022
An opinionated support package for Laravel, that provides flexible and reusable helper methods and traits for commonly used functionality.

Support An opinionated support package for Laravel, that provides flexible and reusable helper methods and traits for commonly used functionality. Ins

Ian Olson 3 Apr 14, 2021
Active State Helper for Laravel Blade

laravel-activehelper Active State Helper for Laravel Blade Lightweight and simple Introduction Basically we do like this. <li class="sidebar {{ Reques

Ahmad Irsyadul Ibad 4 Sep 25, 2022
SEO Helper is a package that provides tools and helpers for SEO (Search Engine Optimization).

SEO Helper By ARCANEDEV© SEO Helper is a package that provides tools and helpers for SEO (Search Engine Optimization). Feel free to check out the rele

ARCANEDEV 301 Nov 25, 2022
Laravel helper to generate the QRcode for ZATCA E-Invoicing system

Laravel-ZATCA Unofficial package to implement ZATCA QRcode for E-Invoicing. Requirements PHP >= 7.4 An mbstring extension Dependencies chillerlan/php-

Moh. Php Master .. 3 Aug 16, 2022
Laravel IDE Helper

Laravel IDE Helper Generator Complete PHPDocs, directly from the source This package generates helper files that enable your IDE to provide accurate a

Barry vd. Heuvel 12.8k Dec 28, 2022
Helper class for working with Laravel Mix in WordPress themes and plugins.

Hybrid\Mix Hybrid Mix is a class for working with Lavarel Mix. It adds helper methods for quickly grabbing asset files cached in the mix-manifest.json

Theme Hybrid 9 Jun 2, 2022
Live Helper Chat - live support for your website. Featuring web and mobile apps, Voice & Video & ScreenShare. Supports Telegram, Twilio (whatsapp), Facebook messenger including building a bot.

Live helper chat It's an open-source powered application, which brings simplicity and usability in one place. With live helper chat you can bring live

Live Helper Chat 1.7k Dec 29, 2022
Laravel Stats Helper

Laravel Stats Helper With laravel-stats-helper you can get the statistics of two values or an array of values. It allows you to get the difference, pe

Label84 24 Jan 25, 2022