Password generator service

v1.3.2 2019-05-27 14:50 UTC

This package is auto-updated.

Last update: 2024-10-25 00:36:49 UTC


README

Codacy Badge Scrutinizer Code Quality Build Status Code Coverage Latest Version on Packagist

DeGraciaMathieu/Riddler

Password generator service

Installation

Run in console below command to download package to your project:

composer require degraciamathieu/riddler

Password generation usage

A password is a set of one or more criteria composed of a dictionary and an occurrence.

The available dictionaries are :

  • AccentedLetter
  • AccentedUppercaseLetter
  • Digit
  • Letter
  • SpecialCharacter
  • UppercaseLetter

Available occurrences :

  • Strict
  • Between
  • None
require 'vendor\autoload.php';

use DeGraciaMathieu\Riddler\Password;
use DeGraciaMathieu\Riddler\Dictionaries;
use DeGraciaMathieu\Riddler\Occurrences;

$password = new Password();
$password->addCriteria(new Dictionaries\Digit(), new Occurrences\Strict(5));
$password->addCriteria(new Dictionaries\Letter(), new Occurrences\Between(3, 6));
$password->generate();

To build passwords faster, it is possible to use a set of prescinded criteria using the formats.

Available formats :

  • LongDigit
  • MixedComplex
  • MixedStrong
  • SmallAlphanumeric
  • StrongAlphanumeric
require 'vendor\autoload.php';

use DeGraciaMathieu\Riddler\Password;
use DeGraciaMathieu\Riddler\Formats;

$password = new Password();
$password->addFormat(new Formats\StrongAlphanumeric());
$password->generate();

It is possible to create its own class format implementing the interface DeGraciaMathieu\Riddler\Contracts\Format

Check password score

It's also possible to check if a passwords matches the required list of criteria with the Score method.

$password = new Password;
$password->addCriteria(new Digit(), new Strict(3));
$password->addCriteria(new Letter(), new Between(3, 5));
$password->score('123abcd'); // 100

$password = new Password;
$password->addCriteria(new Digit(), new Strict(3));
$password->addCriteria(new Letter(), new Between(3, 5));
$password->score('123a'); // 50

The value of the score method being the percentage of validated criteria.

Check password passed

$password = new Password;
$password->addCriteria(new Digit(), new Strict(3));
$password->addCriteria(new Letter(), new Between(3, 5));
$password->passed('123a');

// [
//     ['name' => 'digit_strict_3', 'passed' => true],
//     ['name' => 'letter_between_3_5', 'passed' => false],
// ]
$password = new Password;
$password->addNamedCriteria('MyName', new Digit(), new Strict(3));
$password->passed('123');

// [
//     ['name' => 'MyName', 'passed' => true],
// ]

Examples

Classics

$password = new Password;
$password->addCriteria(new Digit(), new Strict(10));
$password->generate(); // "4731412968"

$password = new Password;
$password->addCriteria(new Letter(), new Strict(20));
$password->generate(); // "tugmdzkgohnnkfrxuqns"

$password = new Password;
$password->addCriteria(new UppercaseLetter(), new Strict(20));
$password->generate(); // "JDXIRCEBWDPZLCWIJNYZ"

$password = new Password;
$password->addCriteria(new UppercaseLetter(), new Between(5, 7));
$password->addCriteria(new Letter(), new Between(5, 7));
$password->generate(); // "xIXPstuqTZmb"

$password = new Password;
$password->addCriteria(new SpecialCharacter(), new Strict(15));
$password->generate(); // "#^_=%§][:@_]^%="

$password = new Password;
$password->addCriteria(new AccentedLetter(), new Strict(15));
$password->generate(); // "üãöîâüîüûàóäùéú"

$password = new Password;
$password->addCriteria(new AccentedUppercaseLetter(), new Strict(15));
$password->generate(); // "ÂÚÏÝÒÌÀÂÜÝÛËÍÊÌ"

$password = new Password;
$password->addCriteria(new Digit(), new Strict(5));
$password->addCriteria(new Letter(), new Strict(5));
$password->addCriteria(new SpecialCharacter(), new Between(5, 10));
$password->generate(); // "!186u;n&~§3r7hb|~?"

$password = new Password;
$password->addCriteria(new Digit(), new Between(5, 7));
$password->addCriteria(new Letter(), new Between(5, 7));
$password->addCriteria(new UppercaseLetter(), new Between(5, 7));
$password->addCriteria(new AccentedLetter(), new Between(5, 7));
$password->addCriteria(new SpecialCharacter(), new Between(5, 7));
$password->generate(); // "uELòp§iO°L§7b~â]3ûë7èm96A"

Formats

$password = new Password();
$password->addFormat(new Formats\LongDigit());
$password->generate(); // "075197457894437657185665450123"

$password = new Password();
$password->addFormat(new Formats\SmallAlphanumeric());
$password->generate(); // "mA5M6ap167gRTeE"

$password = new Password();
$password->addFormat(new Formats\StrongAlphanumeric());
$password->generate(); // "492OHwdJEdDT5Lb89zhY9c26j4XhmX"

$password = new Password();
$password->addFormat(new Formats\MixedStrong());
$password->generate(); // "41súdSXWHV65k2G0lr0õèñzåY"

$password = new Password();
$password->addFormat(new Formats\MixedComplex());
$password->generate(); // "Äûc[%ÀÁkWï_1V8k3uw*3§ÔEaAÍ+5§ôåûWYI6äÕ7"