laminas-password-validator provides a validator for character-set based input validation.

Overview

laminas-password-validator

laminas-password-validator provides a validator for character-set based input validation.

Installation

composer require pragaonj/laminas-password-validator

Usage

The password validator implements laminas Laminas\Validator\ValidatorInterface and can be used like every other laminas validator. The validator requires two options:

  • characterSets contains an array of considered character-sets (possible values are: DIGIT, LETTER, CAPITAL_LETTER, SPECIAL_CHARACTER)
  • numberOfRequiredCharacterSets the number of considered character-sets that need to be present in the password.

General usage

[ PasswordValidator::SPECIAL_CHARACTER, PasswordValidator::LETTER, PasswordValidator::CAPITAL_LETTER, PasswordValidator::DIGIT, ], "numberOfRequiredCharacterSets" => 4, // requires all 4 character-sets to be present in the password ]); $valid = $validator->isValid("myInsecurePassword"); $messages = $validator->getMessages();">
use Pragaonj\Validator\PasswordValidator;

$validator = new PasswordValidator([
    "characterSets" => 
    [
        PasswordValidator::SPECIAL_CHARACTER,
        PasswordValidator::LETTER,
        PasswordValidator::CAPITAL_LETTER,
        PasswordValidator::DIGIT,
    ],
    "numberOfRequiredCharacterSets" => 4, // requires all 4 character-sets to be present in the password
]);

$valid = $validator->isValid("myInsecurePassword");

$messages = $validator->getMessages();

To overwrite the default error message you can set the messageTemplate for msgNotEnoughCharacterSets.

[ PasswordValidator::SPECIAL_CHARACTER, PasswordValidator::LETTER, PasswordValidator::CAPITAL_LETTER, PasswordValidator::DIGIT, ], "numberOfRequiredCharacterSets" => 3, "messageTemplates" => [ PasswordValidator::MSG_NOTENOUGHCHARACTARSETS => "my custom error message" ] ]); $valid = $validator->isValid("myInsecurePassword"); $messages = $validator->getMessages(); // will return ["msgNotEnoughCharacterSets" => "my custom error message"]">
use Pragaonj\Validator\PasswordValidator;

$validator = new PasswordValidator([
    "characterSets" => 
    [
        PasswordValidator::SPECIAL_CHARACTER,
        PasswordValidator::LETTER,
        PasswordValidator::CAPITAL_LETTER,
        PasswordValidator::DIGIT,
    ],
    "numberOfRequiredCharacterSets" => 3,
    "messageTemplates" => [
        PasswordValidator::MSG_NOTENOUGHCHARACTARSETS => "my custom error message"
    ]
]);

$valid = $validator->isValid("myInsecurePassword");

$messages = $validator->getMessages();
// will return ["msgNotEnoughCharacterSets" => "my custom error message"]

Usage in laminas-mvc application

To use the validator in a laminas-mvc application register it as invokable in your module.config.php.

[ "PasswordValidator" => PasswordValidator::class, ] ], ];">
use Pragaonj\Validator\PasswordValidator;

return [
  'validators' => [
    'invokables' => [
        PasswordValidator::class,
    ],
    "aliases" => [
        "PasswordValidator" => PasswordValidator::class,
    ]
  ],
];
You might also like...
File uploads with validation and storage strategies

Upload This component simplifies file validation and uploading. Usage Assume a file is uploaded with this HTML form: form method="POST" enctype="mult

Valitron is a simple, elegant, stand-alone validation library with NO dependencies

Valitron: Easy Validation That Doesn't Suck Valitron is a simple, minimal and elegant stand-alone validation library with NO dependencies. Valitron us

Lightweight and feature-rich PHP validation and filtering library. Support scene grouping, pre-filtering, array checking, custom validators, custom messages. 轻量且功能丰富的PHP验证、过滤库。支持场景分组,前置过滤,数组检查,自定义验证器,自定义消息。

PHP Validate 一个简洁小巧且功能完善的php验证、过滤库。 简单方便,支持添加自定义验证器 支持前置验证检查, 自定义如何判断非空 支持将规则按场景进行分组设置。或者部分验证 支持在进行验证前对值使用过滤器进行净化过滤内置过滤器 支持在进行验证前置处理和后置处理独立验证处理 支持自定义每

[READ-ONLY] Validation library from CakePHP. This repo is a split of the main code that can be found in https://github.com/cakephp/cakephp

CakePHP Validation Library The validation library in CakePHP provides features to build validators that can validate arbitrary arrays of data with eas

Light and extendable schema validation library

Light PHP validation library For everyone who uses MongoDB or other NoSQL solution and cares about what client sends to his/her database and looking f

One Line Validation, For CodeIgniter 4

One Line Validation (OLV) is a package made for CodeIgniter 4 to provide a fast and single line validation experience ideal for CDN and/or API services consuming the Validation System from CodeIgniter 4.

Validation rules for Money and Currency

money-validation-laravel Validation rules for Money and Currency Installation composer require brokeyourbike/money-validation-laravel Usage Package us

高性能的验证器组件(Validation),适用于 Hyperf 或 Laravel 框架,可获得数百倍的性能提升

验证器 简介 兼容 Hyperf/Laravel Validation 规则 部分场景可获得约 500 倍性能提升 验证器可多次复用不同数据,无状态设计 规则可全局复用 智能合并验证规则 安装 环境要求 PHP = 8.0 mbstring 扩展 ctype 扩展 安装命令 composer re

Extension for the Laravel validation class

Intervention Validation Intervention Validation is an extension library for Laravel's own validation system. The package adds rules to validate data l

Releases(v1.0.0)
Owner
null
Abstracts HTTP request input handling, providing an easy interface for data hydration and validation

Linio Input Linio Input is yet another component of the Linio Framework. It aims to abstract HTTP request input handling, allowing a seamless integrat

Linio 41 Dec 12, 2021
🔒 Laravel validation rule that checks if a password has been exposed in a data breach.

?? Laravel Password Exposed Validation Rule This package provides a Laravel validation rule that checks if a password has been exposed in a data breac

Jordan Hall 85 Apr 26, 2022
🔒 Laravel validation rule that checks if a password has been exposed in a data breach.

?? Laravel Password Exposed Validation Rule This package provides a Laravel validation rule that checks if a password has been exposed in a data breac

Jordan Hall 85 Apr 26, 2022
Library that offers Input Filtering based on Annotations for use with Objects. Check out 2.dev for 2.0 pre-release.

DMS Filter Component This library provides a service that can be used to filter object values based on annotations Install Use composer to add DMS\Fil

Rafael Dohms 89 Nov 28, 2022
A powerful schema validator!

MetaYaml A [put your file type here] schema validator using [put another file type here] files. At the moment, file type can be Json, Yaml, or XML. It

Romaric Drigon 100 Sep 28, 2022
Argentinian CUIT and CUIL Validator

CUIT/CUIL Validator Argentinian CUIT and CUIL Rules for laravel validation Installation $ composer require iutrace/laravel-cuit-validator Usage Exampl

iutrace 6 Sep 20, 2022
Custom Laravel Validator for combined unique indexes

unique_with Validator Rule For Laravel This package contains a variant of the validateUnique rule for Laravel, that allows for validation of multi-col

Felix Kiss 383 Oct 18, 2022
MetaYaml - A powerful schema validator

MetaYaml A [put your file type here] schema validator using [put another file type here] files. At the moment, file type can be Json, Yaml, or XML. It

Romaric Drigon 100 Sep 28, 2022
PHP Email address validator - A library for validating emails against several RFC.

EmailValidator A library for validating emails against several RFC. Supported RFCs This library aims to support RFCs: 5321, 5322, 6530, 6531, 6532, 10

Eduardo Gulias Davis 10.7k Jun 13, 2022
Modern PHP validator on steroids for validating forms and/or array's.

Modern PHP Validator - Standalone Validation on Steroids Introduction Head first example Installation Adding fields for validation Execute validation

Kris Kuiper 5 Oct 5, 2022