PHP code example of gabrielesbaiz / password-toolkit

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

    

gabrielesbaiz / password-toolkit example snippets


use Gabrielesbaiz\PasswordToolkit\Facades\PasswordToolkit;

PasswordToolkit::generate();
// => "Goldrake-Mitico-4271"

use Gabrielesbaiz\PasswordToolkit\PasswordToolkit;

echo PasswordToolkit::generate();

PasswordToolkit::generate(10);
// => ["Goldrake-Mitico-4271", "Vespa-Veloce-9921", ...] (array of 10)

PasswordToolkit::generateManyWithReport(5);
// => [['password' => '...', 'report' => StrengthReport], ...]

return [
    'name_types' => [
        'people' => [ /* 49 dictionaries — true/false */ ],
        'things' => [ /* 42 dictionaries — true/false */ ],
    ],

    // Separator between segments. Any symbol, or null.
    'separator_symbol' => '-',

    // Replace spaces in multi-word names with the separator (true)
    // or strip them entirely (false).
    'name_separator' => true,

    // Append a random numeric segment.
    'add_numbers'      => true,
    'numbers_digits'   => 4,           // length of the number
    'numbers_position' => 'end',       // start | middle | end

    // Leetspeak transform: 'no' | 'basic' | 'advanced'.
    'leetspeak_conversion' => 'no',
];

use Gabrielesbaiz\PasswordToolkit\Facades\PasswordToolkit;

// Score an arbitrary password (charset model)
$report = PasswordToolkit::strength('Goldrake-Mitico-4271');
$report->score;              // 0..4
$report->label;              // very_weak | weak | fair | strong | very_strong
$report->entropyBits;        // float
$report->charsetFlags;       // ['lower'=>true,'upper'=>true,'digits'=>true,'symbols'=>true]
$report->crackTimeHuman;     // "12 years"

// Generate + structural report (knowledge of dictionaries — more honest)
['password' => $pwd, 'report' => $report] = PasswordToolkit::generateWithReport();
$report->components;         // ['name'=>x,'adjective'=>y,'number'=>z,'leetspeak_bonus'=>b,'total'=>t]

'strength' => ['guesses_per_second' => 1e12],
bash
php artisan vendor:publish --tag="password-toolkit-config"