Using reCaptcha v2 (No Captcha) on Laravel

Google has launched the new way to verify that your web visitors are not robots. As we know, it’s known as reCaptcha, but on the latest version it’s called No Captcha. Why? Because you don’t have to type anything but only a click on a check box.

Now, I want to show you how to add this captcha to a web application using Laravel framework.

To be straightforward, add this line to your composer.json in section “require”

        "greggilbert/recaptcha": "dev-master"

then run this command

php composer.json update

Next, Add Greggilbert\Recaptcha\RecaptchaServiceProvider to the service provider list in app/config/app.php

Run php artisan config:publish greggilbert/recaptcha

In app/config/packages/greggilbert/recaptcha/config.php, enter your reCAPTCHA public and private keys. You should create a new key pair in order to use No Captcha. (fill the public key with site key).

2014-12-15_1137

Add the following line into app/lang/[lang]/validation.php

"recaptcha" => 'The :attribute field is not correct.',

Open vendor/zizaco/confide/src/views/signup.blade.php

then add this line just after password confirmation div closing tag

{{ Form::captcha() }}

For validation, add these code to app/controllers/user/UserController.php

$rules = array(
 'g-recaptcha-response' => 'required|recaptcha',
 );
 $validator = Validator::make(Input::all(),$rules);
// process the login
 if ($validator->fails()) {
 return Redirect::to('user/create')
 ->withErrors($validator);
 }

Now, time for testing. Open your sign-up page and you will see the new look reCaptcha.

2014-12-15_1126

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: