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.
A bundle to integrate zxcvbn-php with your symfony app. Supports localization and custom matchers.
composer require createnl/zxcvbn-bundle
use Createnl\ZxcvbnBundle\ZxcvbnFactoryInterface;
class PasswordController
{
public function updatePassword(string $password, ZxcvbnFactoryInterface $zxcvbnFactory)
{
$userData = [
'Marco',
'marco@example.com'
];
$zxcvbn = $zxcvbnFactory->createZxcvbn();
$weak = $zxcvbn->passwordStrength($password, $userData);
echo $weak['score']; // will print 0
$strong = $zxcvbn->passwordStrength('correct horse battery staple');
echo $strong['score']; // will print 4
echo $weak['feedback']['warning']; // will print user-facing feedback on the password, set only when score <= 2
echo $weak['feedback']['suggestions']; // may contain user-facing suggestions to improve the score
}
}
This package supports the localization of warning and suggestion messages. Checks on common passwords, words and (family) names are only in English (US). But you can tag your own matcher to extend to your needs.
Supported languages:
More about localization in Symfony.
If you are missing translations in your language you may consider creating (and contribute) them.
Override in your project:
Contributing a language:
messages.LOCALE.yaml (for example messages.es.yaml)If you created your own matcher you can tag them with zxcvbn.matcher in your service container.
services:
App\ZxcvbnMatchers\:
resource: '../src/ZxcvbnMatchers'
tags: ['zxcvbn.matcher']
How can I help you explore Laravel packages today?