PHP code example of pragaonj / laminas-password-validator

1. Go to this page and download the library: Download pragaonj/laminas-password-validator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pragaonj / laminas-password-validator example snippets


use Pragaonj\Validator\PasswordValidator;

$validator = new PasswordValidator([
    "characterSets" => 
    [
        PasswordValidator::SPECIAL_CHARACTER,
        PasswordValidator::LETTER,
        PasswordValidator::CAPITAL_LETTER,
        PasswordValidator::DIGIT,
    ],
    "numberOfRequiredCharacterSets" => 4, // 

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"]

use Pragaonj\Validator\PasswordValidator;

return [
  'validators' => [
    'invokables' => [
        PasswordValidator::class,
    ],
    "aliases" => [
        "PasswordValidator" => PasswordValidator::class,
    ]
  ],
];