Skip to content

Commit d13efca

Browse files
authored
Update readme (#2)
* Add readme * Update readme
1 parent 5571c3e commit d13efca

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/createnl/zxcvbn-bundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/createnl/zxcvbn-bundle/?branch=master)
2+
[![Code Coverage](https://scrutinizer-ci.com/g/createnl/zxcvbn-bundle/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/createnl/zxcvbn-bundle/?branch=master)
3+
[![Build Status](https://travis-ci.com/createnl/zxcvbn-bundle.svg?branch=master)](https://travis-ci.com/createnl/zxcvbn-bundle)
4+
[![Packagist](https://img.shields.io/packagist/dt/createnl/zxcvbn-bundle)](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

Comments
 (0)