Git Product home page Git Product logo

recaptcha's Introduction

Abandoned

All good things must come to an end. The sad fact is that I don't have time to maintain this package, so the release of Laravel 6 is as good as any to make a clean break. You should take a look at the forks to see if anyone is carrying on the torch.

Thanks to everyone for sticking by this package for years!

Recaptcha

A reCAPTCHA Validator for Laravel 5.

(Looking for a Laravel 4 version? Pull the latest 1.x tag. For Laravel 5.0, pull the latest 2.0 tag.)

Installation

Add the following line to the require section of composer.json:

{
    "require": {
        "greggilbert/recaptcha": "dev-master"
    }
}

Setup

  1. In /config/app.php, add the following to providers:
Greggilbert\Recaptcha\RecaptchaServiceProvider::class,

and the following to aliases:

'Recaptcha' => Greggilbert\Recaptcha\Facades\Recaptcha::class,
  1. Run php artisan vendor:publish --provider="Greggilbert\Recaptcha\RecaptchaServiceProvider".
  2. In /config/recaptcha.php, enter your reCAPTCHA public and private keys.
  • If you are not using the most recent version of reCAPTCHA, set version to 1.
  • If you are upgrading to v2 of reCAPTCHA, note that your keys from the previous version will not work, and you need to generate a new set in the reCAPTCHA admin.
  1. The package ships with a default validation message, but if you want to customize it, add the following line into resources/lang/[lang]/validation.php:
    'recaptcha' => 'The :attribute field is not correct.',

Usage

v2 (No Captcha)

  1. In your form, use {!! Recaptcha::render() !!} to echo out the markup.
  2. In your validation rules, add the following:
    $rules = [
        // ...
        'g-recaptcha-response' => 'required|recaptcha',
    ];

v1 (Legacy)

  1. In your form, use {!! Recaptcha::render() !!} to echo out the markup.
  2. In your validation rules, add the following:
    $rules = [
        // ...
        'recaptcha_response_field' => 'required|recaptcha',
    ];

It's also recommended to add required when validating.

Customization

reCAPTCHA v2 allows for customization of the widget through a number of options, listed at the official documentation. You can configure the output of the captcha through six allowed keys: theme, type, lang, callback, tabindex and expired-callback.

In the config file, you can create an options array to set the default behavior. For example:

    // ...
    'options' => [
		'lang' => 'ja',
	],

would default the language in all the reCAPTCHAs to Japanese. If you want to further customize, you can pass options through the render option:

echo Recaptcha::render([ 'lang' => 'fr' ]);

Options passed into Recaptcha::render will always supercede the configuration.

Language

To change the language of the captcha, simply pass in a language as part of the options:

    'options' => [
        'lang' => 'fr',
	],

For a list of valid language codes, consulting the official documentation.

Custom template

Alternatively, if you want to set a default template instead of the standard one, you can use the config:

    // ...
    'template' => 'customCaptcha',

or you can pass it in through the Form option:

echo Recaptcha::render([ 'template' => 'customCaptcha' ]);

v1 customization

For the v1 customization options, consult the old documentation and apply accordingly.

Limitation

Because of Google's way of displaying the reCAPTCHA, this package won't work if you load your form from an AJAX call. If you need to do it, you should use one of the alternate methods provided by Google.

recaptcha's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

recaptcha's Issues

Improvement: readme.md

Although you included the info that Laravel 4.x users have to use the old 1.x branch, you removed the information how to display the captcha on that version.

I checked if you could use the following function in Larvavel 4.2

{{ Recaptcha::render() }}

but it didn't work. Maybe you should add the advice in your Readme.md that Laravel 4.x users / Branch 1.x users have to use the old function

{{ Form::captcha() }}

to get their pages working.

Error!

It's not really a issue someone can help me? I got this error?

ErrorException in CheckRecaptchaV2.php line 41:
file_get_contents(): SSL: Connection reset by peer

recaptcha not displaying

recaptcha is not displaying in the form. when you view the source it shows it was implemented but the data-sitekey attribute it empty.

I did fill them in, in the config.

The g-recaptcha-response field is not correct.

Screenshot:
capture

Code:

$validator = Validator::make(
        array(
            //'username' => Input::get('username'),
            //'email' => Input::get('email'),
            //'password' => Input::get('password'),
            'g-recaptcha-response' => Input::get('g-recaptcha-response'),
        ),
        array(
//          'username' => 'required|alpha_num|unique:users',
//          'email' => 'required|email|unique:users',
            //'password' => 'required|min:5',
            'g-recaptcha-response' => 'required|recaptcha',
            )
    );

This is on Laravel 4.2, using curl driver and recaptcha v2.

Exception not in global namespace.

It's totally possible that I'm doing something wrong, but I recently got a bug report for CheckRecaptcha.php on line 42 yielding a Laravel Orange Screen of Death with the message "Class 'Greggilbert\Recaptcha\Exception' not found".

Does the Exception there just need a backslash preceding it?

Thanks for the plugin!

Move language to own package

Its never a good idea to modify the core language file, as it requires additional work to "upgrade" to the latest core version.

It is possible for a package to have its own language files, which makes the installation/maintenance a little easier :)

Doesn't works dynamic generated

Hello!

I tried to use your plugin with dynamic generated contents ( js -> ajax -> php render tpl with reCaptcha -> respnse to frontend -> frontend opens a modal with respons html string ) but unfortunately it doesn't works.

FatalErrorException

it is showing error like this .. looking for the error and the solution ... Advance thank you Sir..

untitled

Method validateCaptcha Does Not Exist

Hello,

Getting a fatal error thrown when validating a captcha.

BadMethodCallException
Method [validateCaptcha] does not exist.

I added the correct provider to my app/config/app.php and displaying the captcha works fine.

Thanks in advance.

ErrorException Method captcha does not exist

Hello,
im using Laravel 4.2.
Im trying to setup recaptcha and i get this error
"ErrorException
Method captcha does not exist."

ive run php artisan dump-autoload but nothing changed

recaptcha not working for me

I followed your guide on using this recaptcha package but this is the errror i got.
syntax error, unexpected ''custom'' (T_CONSTANT_ENCAPSED_STRING), expecting ')'.
captchaerr

Recaptcha Issue

I have a laravel 5 . I got following error '[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'Greggilbert\Recaptcha\RecaptchaServiceProvider' not found' when run this command "php artisan vendor:publish".

async javascript

Hello,

What about to call the javascript file with async?,
so the script is non-blocking the page load

<script type="text/javascript" async src="//www.google.com/recaptcha/api/challenge?k=<?php echo $public_key ?><?php echo (isset($lang) ? '&hl='.$lang : '') ?>"></script>

or add an option to allow async

Cheers,
J.

How to make language aware?

Is there a way to change the placeholder text of the entry box to handle different languages? Something like specifying the language file.key to use for the text. A quick glance at the code suggests this is not configured at this time - is this correct?

Integration with Reset button?

How can we reset the captcha when the form is reset via the reset button?
Can it be added to the behavior to work with the reset button?

Mass assignment question

Hi,

Great package, I have one question regarding using it with a mass assigned user model. I get an error like this on form submit:

Column not found: 1054 Unknown column 'recaptcha_challenge_field' in 'field list'
(SQL: insert into `users` (`first_name`, `last_name`, `email`, `password`, `gender`, 
`height`, `weight`, `date_of_birth`, `city`, `country`, `recaptcha_challenge_field`, 
`recaptcha_response_field`, `updated_at`, `created_at`)

I think I need to remove the fields protected 'recaptcha_challenge_field' and 'recaptcha_response_field' from assignment and have tried adding them to 'protected $hidden' with no luck.

Any light you can shed on this much appreciated - and it might be worth adding to the install docs for Laravel newbies like me.

Thanks again!

ReCaptcha and REST api

Hello,

Thank you for this great package.

From what I understand, you fetch the "recaptcha_challenge_field" from the input data.

What if there is no input (cause Laravel didn't generate the dom/html) and we simply want to pass a new "recaptcha_challenge_field" value to the model.

Maybe, it will be nice, if the package also checks for a valid attribute in the model ($model-> recaptcha_challenge_field).

Just a thought :)

ErrorException in Recaptcha.php line 26: array_merge(): Argument #1 is not an array

Hi,
I'm using laravel 5 and wanted to use Recaptcha2.

I have installed it but it seems php artisan vendor:publish does nothing. I do not see recaptcha config in my config folder.

Btw when I use {!! Recaptcha::render() !!}

This error is shown:
ErrorException in Recaptcha.php line 26:
array_merge(): Argument #1 is not an array

Kindly check. Thank you.

Method [validateCaptcha] does not exist

Hello,
I have following issue:

'BadMethodCallException' with message 'Method [validateCaptcha] does not exist.' in /vendor/laravel/framework/src/Illuminate/Validation/Validator.php:2547

I am using 1.1.5 version for laravel 4, can you help me with this?

Support for new reCAPTCHA system from google

Recently, google made their new version of reCAPTCHA live. It uses a totally new system for validation. The user first clicks a checkbox widget which pops up the challenge and response section. When they click 'validate', the response is then put into a hidden textarea element and submitted along with the rest of your AJAX or POST data (see https://developers.google.com/recaptcha/docs/verify). You can then check via laravel rules based on your secret and the response, similar to how you do it now, but you only need to use a simple GET request (so you can use file_get_contents() directly to a URL instead of the fsocket request). You no longer have to specify the challenge itself, it's all one giant hash value now.

It would be cool if this were updated to support the new version. I was all set to use your repo in my latest project, but they they suddenly switched up their system.

Change repo's description

Hello,

How about changing the repo's description to contain "Laravel 5" instead of "Laravel 4"? ๐Ÿ˜„

Change captcha field name

Hello,

I want use "captcha" field name instead of "g-recaptcha-response" , how i can edit it in laravel 4 ?

Thanks in advance.

Requesting help with Zizaco/Confide integration due to error

Hi there. I've come here to seek a potential solution to an issue I have. I am running Laravel 4 with the packages:
https://github.com/Zizaco/confide and https://github.com/greggilbert/recaptcha

All the code was fine up to when I added the reCAPTCHA package. When I did, I received this error: http://prntscr.com/478hzd

Here's how I added the package.

  1. Under /vendor/zizaco/confide/src/Zizaco/Confide/ConfideUser.php:
    public static $rules = array(
        'username' => 'required|alpha_dash|unique:users',
        'email' => 'required|email|unique:users',
        'password' => 'required|min:4|confirmed',
        'password_confirmation' => 'min:4',
        'recaptcha_response_field' => 'required|recaptcha', // I added this line.
    );
  1. Under /vendor/zizaco/confide/src/views/signup.php:
        <div class="form-group">
            {{ Form::captcha() }}
        </div>

I can confirm that the public and private keys are correct. Everything has been configured fine. Perhaps it may be that this is being coded incorrectly? Please let me know if you have any ideas. Many thanks.

FatalErrorException in RecaptchaServiceProvider.php

Hi,

I've tried this and I got this error :

Using $this when not in object context

Symfony\Component\Debug\Exception\FatalErrorException
โ€ฆ\vendor\greggilbert\recaptcha\src\Greggilbert\Recaptcha\RecaptchaServiceProvider.php:67

ReCaptcha not filling in g-recaptcha-response field on successful validation

I am not sure if this is a recaptcha issue or an issue with this plugin. However, I add in the captcha field with {{ Form::captcha(); }} and the new NoCaptcha shows up just fine. The tool works and it verifies that I am human. However, when I send it along to my laravel backend the g-recaptcha-response is not sent along.

I checked the form and the g-recaptcha-response field is THERE it just never gets filled with anything. Any ideas?

Problem after a while of working (RecaptchaServiceProvider)

Hi,
I've got very strange problem on one site using your library.
After uploading to server everything works well, after a few minutes (random) it stops. I've got exception: production.ERROR: exception 'ErrorException' with message 'trim() expects parameter 1 to be string, array given' at /vendor/greggilbert/recaptcha/src/Greggilbert/Recaptcha/RecaptchaServiceProvider.php:80

However if I upload RecaptchaServiceProvider again to server it starts to work again for a while.
I compared the RecaptchaServiceProvider before and after issue and it's the same!
Any ideas what could be wrong?
Thanks in advance for assistance.
Regards,
Maciej Matecki

Internationalization doesn't work

I added the options in the config.php file

'options'       => [
        'lang' => 'es'
    ]

I can see in the view the JavaScript Object RecaptchaOptions is

    var RecaptchaOptions = {"lang":"es"};

But the translation doesn't work

Any ideas?

Form::captcha gives Form Class not found

I've just downloaded your package, followed what to do line by line; with laravel 4.1

But once I add {{ Form::captcha() }} it just gives me this fatal error
Symfony \ Component \ Debug \ Exception \ FatalErrorException
Class ' Form' not found

please is this package comptabile with Laravel 4.1 ? if yes how can I solve this problem and use your package ?

Thank you very much

No option for https secure

I installed your package and it's working great except for 1 little thing, you should add an option for https (secure), instead of just hard coding the address "http://www.google.com/recaptcha/api" which is inside your file 'captcha.blade.php'

I would be happy with something like this:
Inside 'config.php':: 'httpPrefix' => 'https' //or http
Inside 'captcha.blade.php':: src={{ $httpPrefix }}//www.google.....

Apart from that, the rest is working as it should... great job :)

Change language

This does not work:
{{ Form::captcha(array('options' => array('lang' => $language ) ) ) }}

Multiple instances of recaptcha?

Hi, I am just wondering if your or anyone else have managed to have multiple instances of recaptcha on the same page?

I think it is probably a limitation with Recaptcha. If you have two with this package you get the following error:

Cannot redeclare renderDataAttributes()

I've tried tweaking the code and also I've tried using another package to test and it only one recaptcha appears.

It would be great if we could do this.

Cheers and thanks for the awesome package.

it doesnt work

I have done all that you said to do in the README but after going through test after test i have found that it does not actually verify and still allows the user to register even if they input the wrong recaptcha.

v2 fallback issue

When v2 of recaptcha falls back to the manual input box, the box moves around the screen quite bizarrely. Not sure if this is a Google issue, the fact I'm on a development server or an issue with your blade views.

screen shot 2014-12-22 at 09 57 58

The curl driver is just returning `false`

I've got an issue where the curl driver is simply returning false.
The native driver is working fine though.
Any ideas?

all default package configs.
php 5.5.9-1ubuntu4.5

Usage problem

I try to use this package but i got some problems on validate
This is my code:
$validate = Validator::make(
array('recaptcha_response_field' => 'required|recaptcha')
);
if ($validate->fails())
{
echo $validate->messages();
}

I got some errors. How do i validate the rechaptcha?

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.