Add the following in your composer.json:
{
"require": {
"jbafford/password-strength-bundle": "^1.0"
}
}
Or,
./composer.phar require jbafford/password-strength-bundle dev-master
To start using the bundle, register the bundle in your application's kernel class:
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Bafford\PasswordStrengthBundle\BaffordPasswordStrengthBundle(),
);
)
If you are using annotations for validations, include the constraints namespace:
use Bafford\PasswordStrengthBundle\Validator\Constraints as BAssert;
and then add the PasswordStrength
validator to the relevant field:
/**
* @BAssert\PasswordStrength(minLength=7, requireNumbers=true)
*/
protected $password;
Default options include:
- minLength = 5
- requireLetters = true
- requireCaseDiff = false
- requireNumbers = false
- requireSpecials = false
You can customize the validation error messages:
- tooShortMessage = 'Your password must be at least {{length}} characters long.'
- missingLettersMessage = 'Your password must include at least one letter.'
- requireCaseDiffMessage = 'Your password must include both upper and lower case letters.'
- missingNumbersMessage = 'Your password must include at least one number.'
- missingSpecialsMessage = 'Your password must include at least one special character.'