jblab / password-validator-bundle
Validates a password based on certain criteria.
Installs: 132
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 1
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^8.1
- symfony/config: ^6.4 || ^7.0
- symfony/dependency-injection: ^6.4 || ^7.0
- symfony/http-kernel: ^6.4 || ^7.0
Requires (Dev)
- symfony/framework-bundle: ^6.4 || ^7.0
- symfony/phpunit-bridge: ^6.4 || ^7.0
- symfony/yaml: ^6.4 || ^7.0
README
Password Validator Bundle is a Symfony package to help you validate passwords against customizable criteria with ease.
Installation
Applications that use Symfony Flex
Open a command console, enter your project directory and execute:
composer require jblab/password-validator-bundle
Applications that don't use Symfony Flex
Step 1: Download the Bundle
Open 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-bundle
Step 2: Enable the Bundle
Then, 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], ];
Usage
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
.
Configuration
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: null
Contributing
We 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.
License
This bundle is released under the Apache 2.0 License. Feel free to use it in your projects.