2017 © Pedro Peláez
 

package captcha

Laravel 5 Captcha Package

image

mews/captcha

Laravel 5 Captcha Package

  • Wednesday, April 25, 2018
  • by mewebstudio
  • Repository
  • 46 Watchers
  • 1150 Stars
  • 356,313 Installations
  • PHP
  • 24 Dependents
  • 0 Suggesters
  • 238 Forks
  • 42 Open issues
  • 20 Versions
  • 11 % Grown

The README.md

Captcha for Laravel 10/11

Build Status Scrutinizer Code Quality Latest Stable Version Latest Unstable Version License Total Downloads, (*1)

A simple Laravel 5/6 service provider for including the Captcha for Laravel., (*2)

for Laravel 4 Captcha for Laravel Laravel 4, (*3)

for Laravel 5 to 9 Captcha for Laravel Laravel 4, (*4)

Preview

Preview, (*5)

Installation

The Captcha Service Provider can be installed via Composer by requiring the mews/captcha package and setting the minimum-stability to dev (required for Laravel 5) in your project's composer.json., (*6)

{
    "require": {
        "laravel/framework": "5.0.*",
        "mews/captcha": "~3.0"
    },
    "minimum-stability": "stable"
}

or, (*7)

Require this package with composer:, (*8)

composer require mews/captcha

Update your packages with composer update or install with composer install., (*9)

In Windows, you'll need to include the GD2 DLL php_gd2.dll in php.ini. And you also need include php_fileinfo.dll and php_mbstring.dll to fit the requirements of mews/captcha's dependencies., (*10)

Usage

To use the Captcha Service Provider, you must register the provider when bootstrapping your Laravel application. There are essentially two ways to do this., (*11)

Find the providers key in config/app.php and register the Captcha Service Provider., (*12)

    'providers' => [
        // ...
        'Mews\Captcha\CaptchaServiceProvider',
    ]

for Laravel 5.1+, (*13)

    'providers' => [
        // ...
        Mews\Captcha\CaptchaServiceProvider::class,
    ]

Find the aliases key in config/app.php., (*14)

    'aliases' => [
        // ...
        'Captcha' => 'Mews\Captcha\Facades\Captcha',
    ]

for Laravel 5.1+, (*15)

    'aliases' => [
        // ...
        'Captcha' => Mews\Captcha\Facades\Captcha::class,
    ]

For Laravel 11 : you do not need to add the alias, it will be added automatically., (*16)

Configuration

Custom settings:

To use your own settings, publish config., (*17)

$ php artisan vendor:publish, (*18)

config/captcha.php, (*19)

return [
    'default'   => [
        'length'    => 5,
        'width'     => 120,
        'height'    => 36,
        'quality'   => 90,
        'math'      => true,  //Enable Math Captcha
        'expire'    => 60,    //Captcha expiration
    ],
    // ...
];

Disable validation:

To disable the captcha validation use CAPTCHA_DISABLE environment variable. e.g. .env config:, (*20)

CAPTCHA_DISABLE=true

Example Usage

Session Mode:

    // [your site path]/Http/routes.php
    Route::any('captcha-test', function() {
        if (request()->getMethod() == 'POST') {
            $rules = ['captcha' => 'required|captcha'];
            $validator = validator()->make(request()->all(), $rules);
            if ($validator->fails()) {
                echo '<p style="color: #ff0000;">Incorrect!</p>';
            } else {
                echo '<p style="color: #00ff30;">Matched :)</p>';
            }
        }

        $form = '<form method="post" action="captcha-test">';
        $form .= '<input type="hidden" name="_token" value="' . csrf_token() . '">';
        $form .= '<p>' . captcha_img() . '</p>';
        $form .= '<p><input type="text" name="captcha"></p>';
        $form .= '<p><button type="submit" name="check">Check</button></p>';
        $form .= '</form>';
        return $form;
    });

Detailed Example in Laravel way view files, (*21)

    //register.blade.php
    <img src="{{ captcha_src() }}" alt="captcha">
        <div class="mt-2"></div>
        <input 
            type="text" name="captcha" class="form-control @error('captcha') is-invalid @enderror" placeholder="Please Insert Captch"
            >
         @error('captcha') 
         <div class="invalid-feedback">{{ $message }}</div> @enderror 

controller files, (*22)

        Validator::make($input, [
            'name' => ['required', 'string', 'max:255'],
            'email' => [
                'required',
                'string',
                'email',
                'max:255',
                Rule::unique(User::class),
            ],
            'password' => $this->passwordRules(),
            'captcha' => 'required|captcha'
        ])->validate();

Stateless Mode:

You get key and img from this url http://localhost/captcha/api/math and verify the captcha using this method:, (*23)

    //key is the one that you got from json response
    // fix validator
    // $rules = ['captcha' => 'required|captcha_api:'. request('key')];
    $rules = ['captcha' => 'required|captcha_api:'. request('key') . ',math'];
    $validator = validator()->make(request()->all(), $rules);
    if ($validator->fails()) {
        return response()->json([
            'message' => 'invalid captcha',
        ]);

    } else {
        //do the job
    }

Return Image

captcha();

or, (*24)

Captcha::create();

Return URL

captcha_src();

or, (*25)

Captcha::src('default');

Return HTML

captcha_img();

or, (*26)

Captcha::img();

To use different configurations

captcha_img('flat');

Captcha::img('inverse');

etc., (*27)

Based on Intervention Image, (*28)

^_^, (*29)

The Versions

25/04 2018
28/02 2018

dev-master-l4

dev-master-l4 http://github.com/mewebstudio/captcha

Captcha Package for Laravel 4

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sam Yong

laravel laravel 4 security captcha l4 captcha image mecaptcha

28/02 2018

1.0.2

1.0.2.0 http://github.com/mewebstudio/captcha

Captcha Package for Laravel 4

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sam Yong

laravel laravel 4 security captcha l4 captcha image mecaptcha

11/09 2017
08/08 2017
19/07 2016
19/07 2016
30/05 2016
26/04 2016
25/01 2014

1.0.1

1.0.1.0 http://github.com/mewebstudio/captcha

Captcha Package for Laravel 4

  Sources   Download

MIT

The Requires

 

laravel laravel 4 security captcha l4 captcha image mecaptcha