Thursday, 25 October 2018

How to add google captcha in laravel


First, install anhskohbo/no-captcha Package for Google reCaptcha code. Using this Package, we can generate reCaptcha code for our Application.

composer require anhskohbo/no-captcha

Type below command to Publish Config File
php artisan vendor:publish --provider="Anhskohbo\NoCaptcha\NoCaptchaServiceProvider"


In Env file add these lines

NOCAPTCHA_SECRET=6LfAxnYUAAAAAMFIDoHDyukSi4yHcYZp8q5WdB2m
NOCAPTCHA_SITEKEY=6LfAxnYUAAAAAH5JZ5xlK_iTjjkbdupMuvKeszYZ

Add this lines to your register or login page.

<div class="row">
          <div class="col-md-4"></div>
          <div class="form-group col-md-4">
          <label for="ReCaptcha">Recaptcha:</label>
          {!! NoCaptcha::renderJs() !!}
          {!! NoCaptcha::display() !!}
            </div>
        </div>
 
Add in LoginContorller.php 
protected function validateLogin(Request $request)
    {   
         $this->validate($request,[
            'email' => ['required''string''email'],
            'password' => ['required''string'],
            'g-recaptcha-response' => ['required','captcha'],
        ]);
    }





2 comments:

  1. Thank you for sharing this informative post on laravel. I am new to laravel and this post will really help me.
    Laravel Web Development Services

    ReplyDelete
  2. Tecocraft Ltd has been empowering for creating custom Mobile App Development Company In UK. and solutions for customers willing to grow their business and want to provide a great user experience to end users.

    ReplyDelete

Machine Learning - Potato Leaf Disease Prediction

Step 1: import numpy as np import pandas as pd import splitfolders import matplotlib.pyplot as plt import tensorflow as tf from tensorflow i...