PHP code example of customergauge / password

1. Go to this page and download the library: Download customergauge/password 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/ */

    

customergauge / password example snippets


use Customergauge\Password\Rule\Lowercase;
use Customergauge\Password\Exception\InvalidPassword;

$validate = new Lowercase;
$password = "UPPERCASE";

try {
    $validate($password);
} catch (InvalidPassword $e) {
    echo $e->getMessage();
}

// output: Password should have at least 1 lowercase character(s) but 0 found.

use Customergauge\Password\Rule\Lowercase;
use Customergauge\Password\Rule\Uppercase;
use Customergauge\Password\Rule\Length;
use Customergauge\Password\RuleChain;
use Customergauge\Password\Exception\InvalidPassword;

$validate = new RuleChain(
  new Lowercase(2),
  new Uppercase(2),
  new Length(10),
  new Digit(3)
);

$password = "ABcd00efgh";

try {
    $validate($password);
} catch (InvalidPassword $e) {
    echo $e->getMessage();
}

// output: Password should have at least 3 digit character(s) but 2 found.

use Customergauge\Password\Rule\Lowercase;
use Customergauge\Password\Rule\Uppercase;
use Customergauge\Password\Rule\Length;
use Customergauge\Password\RuleChain;
use Customergauge\Password\Exception\InvalidPassword;

$validate = new PersistRuleChain(
  new Lowercase(2),
  new Uppercase(2),
  new Length(10),
  new Digit(3)
);

$password = "ABcd00efgh";

if ($validate($password)) {
    echo "valid";
} else {
    echo "invalid";
    // It is possible to get all exceptions using $validate->exceptions();
}

// output: invalid