|
| 1 | +[](https://scrutinizer-ci.com/g/createnl/zxcvbn-bundle/?branch=master) |
| 2 | +[](https://scrutinizer-ci.com/g/createnl/zxcvbn-bundle/?branch=master) |
| 3 | +[](https://travis-ci.com/createnl/zxcvbn-bundle) |
| 4 | +[](https://packagist.org/packages/createnl/zxcvbn-bundle) |
| 5 | + |
| 6 | +# Zxcvbn Symfony Bundle |
| 7 | +A bundle to integrate [zxcvbn-php](https://github.com/bjeavons/zxcvbn-php) with your symfony app. Supports localization and custom matchers. |
| 8 | + |
| 9 | +## Installation |
| 10 | +```bash |
| 11 | +composer require createnl/zxcvbn-bundle |
| 12 | +``` |
| 13 | + |
| 14 | +## Basic Usage |
| 15 | +```php |
| 16 | +use Createnl\ZxcvbnBundle\ZxcvbnFactoryInterface; |
| 17 | + |
| 18 | +class PasswordController |
| 19 | +{ |
| 20 | + public function updatePassword(string $password, ZxcvbnFactoryInterface $zxcvbnFactory) |
| 21 | + { |
| 22 | + $userData = [ |
| 23 | + 'Marco', |
| 24 | + 'marco@example.com' |
| 25 | + ]; |
| 26 | + |
| 27 | + $zxcvbn = $zxcvbnFactory->createZxcvbn(); |
| 28 | + |
| 29 | + $weak = $zxcvbn->passwordStrength($password, $userData); |
| 30 | + echo $weak['score']; // will print 0 |
| 31 | + |
| 32 | + $strong = $zxcvbn->passwordStrength('correct horse battery staple'); |
| 33 | + echo $strong['score']; // will print 4 |
| 34 | + |
| 35 | + echo $weak['feedback']['warning']; // will print user-facing feedback on the password, set only when score <= 2 |
| 36 | + echo $weak['feedback']['suggestions']; // may contain user-facing suggestions to improve the score |
| 37 | + } |
| 38 | +} |
| 39 | +``` |
| 40 | + |
| 41 | +## Localization |
| 42 | +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](#extending-matchers) to extend to your needs. |
| 43 | + |
| 44 | +Supported languages: |
| 45 | +- Dutch 🇳🇱 |
| 46 | +- English 🇺🇸 |
| 47 | + |
| 48 | +[More about localization in Symfony.](https://symfony.com/doc/current/translation.html#configuration) |
| 49 | + |
| 50 | +## Adding translations |
| 51 | +If you are missing translations in your language you may consider creating (and contribute) them. |
| 52 | + |
| 53 | +Override in your project: |
| 54 | +1. Open [messages.en.yaml](src/Resources/translations/messages.en.yaml) |
| 55 | +2. Copy the contents to your project's translation file |
| 56 | +3. Change to your needs |
| 57 | + |
| 58 | +Contributing a language: |
| 59 | +1. Fork this repository |
| 60 | +2. Copy [messages.en.yaml](src/Resources/translations/messages.en.yaml) |
| 61 | +3. Change the filename to `messages.LOCALE.yaml` (for example `messages.fr.yaml`) |
| 62 | +4. Open it up and translate the right-hand values to your language |
| 63 | +5. Create a Pull Request |
| 64 | +6. Thank you! |
| 65 | + |
| 66 | +## Extending matchers |
| 67 | +If you created your own matcher you can tag them with `zxcvbn.matcher` in your service container. |
| 68 | +```yaml |
| 69 | +services: |
| 70 | + App\ZxcvbnMatchers\: |
| 71 | + resource: '../src/ZxcvbnMatchers' |
| 72 | + tags: ['zxcvbn.matcher'] |
| 73 | +``` |
0 commit comments