Git Product home page Git Product logo

laravel-math-captcha's Introduction

Very simple math captcha for Laravel5

A simple math question (+,-,*) to validate user input.

Installation

composer require elic-dev/laravel-math-captcha

Setup Laravel > 5.5

This package supports Laravel Package Auto-Discovery.

Setup Laravel <= 5.4

You can add the ServiceProvider to the providers array in app/config/app.php.

ElicDev\MathCaptcha\MathCaptchaServiceProvider::class,

Usage

This package only returns the question and the input. You have to position it within your labels and form classes.

{{ app('mathcaptcha')->label() }}
{!! app('mathcaptcha')->input() !!}

Display it wihtin Bootstrap as example:

<div class="form-group">
    <label for="mathgroup">Please solve the following math function: {{ app('mathcaptcha')->label() }}</label>
    {!! app('mathcaptcha')->input(['class' => 'form-control', 'id' => 'mathgroup']) !!}
    @if ($errors->has('mathcaptcha'))
        <span class="help-block">
            <strong>{{ $errors->first('mathcaptcha') }}</strong>
        </span>
    @endif
</div>

Looks like

MathCaptcha Bootstrap

Validation

Add 'mathcaptcha' => 'required|mathcaptcha' to rules array.

$this->validate($request, [
    'mathcaptcha' => 'required|mathcaptcha',
]);

Add corresponding translation string to your lang/validation.php files.

Reset

This package does not generate a new math question for each request. Once the form has been submited without validation erros you can reset the library to force generate a new question.

app('mathcaptcha')->reset();

Configuration

Operands, Min, Max

You can adjust the available operands (+,-,*) and minimum or maximum randum values used. Some users might stuggle with more complex math operations.

php artisan vendor:publish --provider="ElicDev\MathCaptcha\MathCaptchaServiceProvider" --tag=config

Display as text

It is possible to show the math question as text (e.g. "Four plus Five"). You can adjust a setting in the config file. This requires translations and a language files. A few languages are provided with this package.

php artisan vendor:publish --provider="ElicDev\MathCaptcha\MathCaptchaServiceProvider" --tag=lang

laravel-math-captcha's People

Contributors

hnnweb avatar ibnuridho avatar l1lle avatar

Watchers

 avatar

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.