https://github.com/zerosdev/laravel-captcha
Laravel Captcha Generator
https://github.com/zerosdev/laravel-captcha
captcha laravel php php-captcha-generator
Last synced: 6 months ago
JSON representation
Laravel Captcha Generator
- Host: GitHub
- URL: https://github.com/zerosdev/laravel-captcha
- Owner: zerosdev
- License: mit
- Created: 2019-12-09T17:07:42.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-25T10:18:31.000Z (about 6 years ago)
- Last Synced: 2025-10-05T13:28:40.238Z (6 months ago)
- Topics: captcha, laravel, php, php-captcha-generator
- Language: PHP
- Homepage: https://www.zeros.co.id
- Size: 242 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Laravel Captcha
Laravel Captcha Generator
## Requirements
- PHP 5.6+
- Laravel Framework 5.2+
- GD Library enabled
## Installation
- Run
composer require zerosdev/laravel-captcha:dev-master
- Add this code to your **config/app.php** in providers array
ZerosDev\LaravelCaptcha\ServiceProvider::class,
- Add this code to your **config/app.php** in aliases array
'Captcha' => ZerosDev\LaravelCaptcha\Facade::class,
- Run
composer dump-autoload
- Run
php artisan vendor:publish --provider="ZerosDev\LaravelCaptcha\ServiceProvider"
## Configuration
Open your **config/captcha.php** and adjust the setting. Optionally, you can adjust some captcha setting on-the-fly with available methods below:
#### chars(String)
Set the characters that will be used as captcha text
#### size(Integer width, Integer height)
Set the captcha image width and height in pixel (px)
#### length(Integer)
Set the captcha character length
## Generation Example
// Import from root class (Captcha Facade)
use Captcha;
// generate captcha
$captcha = Captcha::chars('123456789ABCDEFGHIJKLMNPQRSTUVWXYZ')->length(4)->size(120, 40)->generate();
// get captcha id
$id = $captcha->id();
// return random generation id
// print html hidden form field, used in blade template
{{ $captcha->form_field() }}
// return: <input type="hidden" name="captcha_id" value="XXXXXXXXXXXXXX" id="captcha_id">
// get base64 image
$image = $captcha->image();
// return data:image/png; base64,XXXXXXXXXXXXXX
// print html image, used in blade template
{{ $captcha->html_image(['onclick' => 'jsFunction()', 'style' => 'border:1px solid #ddd']) }}
// return: <img src="data:image/png; base64,XXXXXXXXXXXXXX" onclick="jsFunction()" style="border:1px solid #ddd" />
## Validation
// Import from root class (Captcha Facade)
use Captcha;
// validate captcha
// $captchaId = Captcha generation id, $captcha->id()
// $captchaText = Captcha input from client request
if( Captcha::validate($captchaId, $captchaText) )
{
// Valid
}
else
{
// Invalid
}
## Advise
It is recommended to avoid using the "0" (zero) and "O" characters in captcha to avoid being ambiguous