createnl / zxcvbn-bundle
zxcvbn-php symfony bundle
Installs: 13 070
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 4
Forks: 4
Open Issues: 1
Type:symfony-bundle
Requires
- php: ^8.0
- bjeavons/zxcvbn-php: ^1.3
- symfony/translation: ^5.4|^6.0|^7.0
Requires (Dev)
- phpunit/phpunit: ^9.5
- symfony/console: ^5.4|^6.0|^7.0
- symfony/framework-bundle: ^5.4|^6.0|^7.0
This package is not auto-updated.
Last update: 2024-11-21 20:03:59 UTC
README
Zxcvbn Symfony Bundle
A bundle to integrate zxcvbn-php with your symfony app. Supports localization and custom matchers.
Installation
composer require createnl/zxcvbn-bundle
Basic Usage
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 } }
Localization
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:
- Dutch π³π±
- English πΊπΈ
- French π«π·
More about localization in Symfony.
Adding translations
If you are missing translations in your language you may consider creating (and contribute) them.
Override in your project:
- Open messages.en.yaml
- Copy the contents to your project's translation file
- Change to your needs
Contributing a language:
- Fork this repository
- Copy messages.en.yaml
- Change the filename to
messages.LOCALE.yaml
(for examplemessages.es.yaml
) - Open it up and translate the right-hand values to your language
- Create a Pull Request
- Thank you!
Extending matchers
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']