blackcube / powshield
Blackcube POW Shield for Yii2
1.0.0
2024-06-22 13:18 UTC
Requires
- php: >=8.0
- ext-dom: *
- ext-fileinfo: *
- ext-intl: *
- ext-json: *
- vlucas/phpdotenv: ~5.4
- yiisoft/yii2: ~2.0.13
Requires (Dev)
- codeception/codeception: ~5.0
- codeception/module-asserts: ~2.0
- codeception/module-yii2: ~1.1
- yiisoft/yii2-debug: ~2.1
- yiisoft/yii2-gii: ~2.2
This package is auto-updated.
Last update: 2024-09-22 13:47:10 UTC
README
安装
安装此扩展的首选方式是通过 composer.
composer require blackcube/powshield
配置
将以下代码添加到您的配置文件中
return [ // ... 'modules' => [ // ... 'powshield' => [ 'class' => 'blackcube\powshield\Module', 'key' => 'your-secret-key', 'algorithm' => 'SHA-256', // SHA-256, SHA-384, SHA-512 'minIterations' => 1000, // change iterations to make the process slower 'maxIterations' => 100000, 'saltLength' => 12, // change salt length to make the process slower 'antiReplay' => true, // enable anti-replay mechanism, needs app to have cache component 'antiReplayTimeout' => 300, // duration of the anti-replay mechanism 'timeValidity' => 300, // duration of the challenge validity ], ], 'bootstrap' => [ // ... 'powshield' ], ];
这将设置模块并
- 激活 API 路由
/powshield/generate-challenge
用于生成挑战/powshield/verify-solution
用于检查解决方案
- 激活验证器
powshield
用于在模型中验证解决方案
用法
客户端
您可以使用以下库来生成和检查解决方案
- @blackcube/aurelia2-powshield Aurelia 2 powshield
- @blackcube/vanilla-powshield VanillaJS powshield
一旦生成了解决方案,您应该将其发送到服务器
服务器端
您可以使用以下代码来验证解决方案
class MyModel extends yii\base\Model { public $captchaSolution; public $name; public function rules() { return [ [['captchaSolution', 'name'], 'required'], ['captchaSolution', 'powshield'], ]; } }
如果解决方案无效,模型将在 captchaSolution
上出现错误。