kilofox / hyperf-captcha
A captcha component for Hyperf.
v1.0.1
2022-09-15 02:13 UTC
Requires
- php: >=7.4
- hyperf/http-message: ^2.2
- hyperf/utils: ^2.2
- psr/simple-cache: ^1.0
- symfony/string: ^5.3|^6.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
This is the Captcha component for Hyperf 3.
Installation
$ composer require muffetlab/hyperf-captcha
Publish
$ php bin/hyperf.php vendor:publish muffetlab/hyperf-captcha
Upgrading
This version targets Hyperf 3 and contains breaking changes:
- PHP >= 8.0 and Hyperf ^3.0 are required.
- The
fontpathconfig option has been renamed tofont_path. If you have previously published the config, updateconfig/autoload/captcha.phpaccordingly, or re-publish it with the command above. Hyperf\Utils\ApplicationContexthas been deprecated by Hyperf; useHyperf\Context\ApplicationContextinstead.
Usage
Instantiate captcha factory:
use Hyperf\Context\ApplicationContext;
use Muffetlab\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