kilofox/hyperf-captcha

A captcha component for Hyperf.

v1.0.1 2022-09-15 02:13 UTC

This package is auto-updated.

Last update: 2024-04-15 06:14:59 UTC


README

This is the Captcha component for Hyperf 2.

Release Version Latest Release Download Total Download

Installation

$ composer require kilofox/hyperf-captcha

Publish

$ php bin/hyperf.php vendor:publish kilofox/hyperf-captcha

Usage

Instantiate captcha factory:

use Hyperf\Utils\ApplicationContext;
use Kilofox\Captcha\CaptchaFactory;

$captchaFactory = ApplicationContext::getContainer()->get(CaptchaFactory::class);

Render a captcha:

$key = $this->request->query('key');
$captcha = $captchaFactory->create($key);

return $captcha->render();

Validate the captcha:

$key = $this->request->input('key', '');
$captcha = $this->request->input('captcha', '');

$captchaFactory->validate($key, $captcha);

Supported Captcha Styles

  • alpha
  • basic
  • black
  • math
  • riddle
  • word