blackcube / powshield
Blackcube POW Shield for Yii2
Installs: 56
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:yii2-extension
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-08-22 13:43:03 UTC
README
Installation
The preferred way to install this extension is through composer.
composer require blackcube/powshield
Configuration
Add the following code to your configuration file:
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' ], ];
This sets up the module and:
- activate api routes:
/powshield/generate-challenge
to generate a challenge/powshield/verify-solution
to check a solution
- activate the validator:
powshield
to validate a solution in a model
Usage
Client side
You can use the following libraries to generate and check the solution:
- @blackcube/aurelia2-powshield Aurelia 2 powshield
- @blackcube/vanilla-powshield VanillaJS powshield
Once solution is generated, you should send it to the server
Server side
You can use the following code to validate a solution:
class MyModel extends yii\base\Model { public $captchaSolution; public $name; public function rules() { return [ [['captchaSolution', 'name'], 'required'], ['captchaSolution', 'powshield'], ]; } }
If the solution is not valid, the model will have an error on captchaSolution
.