createnl/zxcvbn-bundle
Symfony bundle integrating zxcvbn-php for password strength scoring with user-data hints, localized feedback (EN/NL/FR), and support for custom matchers. Provides a factory service to create a Zxcvbn instance for easy use in controllers and services.
Strengths:
Fit for Laravel:
laravel-zxcvbn), given its clean architecture.illuminate/validation with basic rules, but lacks context-aware strength scoring (e.g., user data, dictionary attacks).Core Components:
ZxcvbnFactoryInterface (factory pattern).translator service).zxcvbn.matcher) for extensibility.Laravel Equivalents:
| Symfony Feature | Laravel Equivalent | Feasibility |
|---|---|---|
ZxcvbnFactoryInterface |
Laravel Service Container + Facade | High (use bind() in AppServiceProvider) |
| Translation System | Laravel’s trans() helper + JSON files |
High (adapt messages.en.yaml to Laravel’s resources/lang) |
| Service Tags | Laravel’s tags() in register() |
Medium (custom logic needed) |
| Event System | Laravel Events | High (direct mapping) |
Key Dependencies:
tags with manual service registration).ZxcvbnValidator) that exposes the same interface as the Symfony bundle.zxcvbn-php, then wrap it in a Laravel package.zxcvbn-php (e.g., new attack patterns) be handled?spatie/laravel-password-strength) or build from scratch?zxcvbn-php (core library) is Laravel-agnostic.translation and dependency-injection can be replaced with Laravel equivalents.tags() helper).ZxcvbnFactory in AppServiceProvider:
$this->app->bind(ZxcvbnFactoryInterface::class, function ($app) {
return new ZxcvbnFactory(new zxcvbn\zxcvbn());
});
Validator to use zxcvbn:
Validator::extend('zxcvbn', function ($attribute, $value, $parameters, $validator) {
$zxcvbn = app(ZxcvbnFactoryInterface::class)->createZxcvbn();
$result = $zxcvbn->passwordStrength($value);
return $result['score'] >= (int)$parameters[0]; // e.g., score >= 3
});
messages.en.yaml to resources/lang/en/zxcvbn.php and use Laravel’s trans() helper.Phase 1: Standalone Integration
zxcvbn-php directly:
composer require bjeavons/zxcvbn-php
use zxcvbn\zxcvbn;
$zxcvbn = new zxcvbn();
$result = $zxcvbn->passwordStrength('password123');
Phase 2: Laravel Wrapper
laravel-zxcvbn) with:
ZxcvbnServiceProvider (registers factory, validator rule).ZxcvbnValidator (extends Laravel’s Validator).resources/lang/)./laravel-zxcvbn
/src
ZxcvbnServiceProvider.php
Rules/Zxcvbn.php
/config
zxcvbn.php
/lang
en/zxcvbn.php
Phase 3: Bundle Adaptation (Optional)
createnl/zxcvbn-bundle and:
ContainerBuilder with Laravel’s Container.translator with Laravel’s trans().tags with Laravel’s tags() helper.createnl/laravel-zxcvbn-bundle).| Feature | Symfony Bundle | Laravel Adaptation | Notes |
|---|---|---|---|
| Password Strength | ✅ passwordStrength() |
✅ Direct zxcvbn call |
No changes needed. |
| Localization | ✅ Translation files | ✅ Laravel lang/ files |
Manual mapping required. |
| Custom Matchers | ✅ Service tags | ⚠️ Manual registration | Need to implement ZxcvbnMatcher trait. |
| Symfony Events | ✅ EventDispatcher | ✅ Laravel Events | Direct replacement. |
| DI Container | ✅ Symfony-specific | ✅ Laravel Container | Factory pattern works cross-framework. |
min:8, regex:/[A-Z]/).zxcvbn-php standalone in a single controller/form.How can I help you explore Laravel packages today?