Password Validator Bundle is a Symfony package to help you validate passwords against customizable criteria with ease.
Open a command console, enter your project directory and execute:
composer require jblab/password-validator-bundleOpen a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
composer require jblab/password-validator-bundleThen, enable the bundle by adding it to the list of registered bundles
in the config/bundles.php file of your project:
// config/bundles.php
return [
// ...
Jblab\PasswordValidatorBundle\JblabPasswordValidatorBundle::class => ['all' => true],
];This bundle provides a single service for validating passwords, which
you can autowire by using the PasswordValidatorInterface type-hint:
// src/Controller/SomeController.php
use Jblab\PasswordValidatorBundle\PasswordValidatorInterface;
// ...
class SomeController
{
public function __construct(private readonly PasswordValidatorInterface $passwordValidator)
{
}
public function index()
{
$password = 'StrongPass1!';
$isValid = $this->passwordValidator->validate($password);
if (!$isValid) {
// Handle invalid password, e.g., return error response
}
// Continue with your logic for valid passwords
}
}You can also access this service directly using the id
jblab_password_validator.password_validator.
To customize password validation criteria, add the configuration file config/packages/jblab_password_validator.yaml
with the following options (default values shown):
# config/packages/jblab_password_validator.yaml
jblab_password_validator:
# Minimum password length.
minimum_length: 8
# Maximum password length.
maximum_length: 64
# Whether or not to require a special character.
require_special_character: true
# Whether or not to require a uppercase letter.
require_uppercase: true
# Whether or not to require a lowercase letter.
require_lowercase: true
# Whether or not to require a number.
require_number: true
# String containing all valid special characters
special_character_set: '!@#$%^&*()_+-=[]{}|'''
# String containing all invalid characters
excluded_character_set: nullWe love contributions! If you have an idea for a feature, feel free to open an issue or, better yet, submit a pull request. We welcome participation, whether you're submitting code, reporting bugs, or asking questions. Check out the contribution guidelines to get started.
This bundle is released under the Apache 2.0 License. Feel free to use it in your projects.
