PHP code example of darkv / php-password-generator

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

    

darkv / php-password-generator example snippets




// Import the namespace
use \Darkv\PhpPasswordGenerator\PasswordGenerator;

// create instance with an English word list
$gen = PasswordGenerator::EN();

// generate a password
echo $gen->generate();



use \Darkv\PhpPasswordGenerator\PasswordGenerator;

// create instance with English word list
$gen = PasswordGenerator::EN();

// create instance with German word list
$gen = PasswordGenerator::DE();

// create instance with custom parameters
$gen = new PasswordGenerator([
    'url'       => 'https://www.tagesschau.de/newsticker.rdf',
    'minLength' => 3,
    'maxLength' => 6,
]);



use \Darkv\PhpPasswordGenerator\PasswordGenerator;

$gen = PasswordGenerator::EN();

// reuse word list without rebuilding
echo 'Password 1: ', $gen->generate();
echo 'Password 2: ', $gen->generate();
echo 'Password 3: ', $gen->generate();



use \Darkv\PhpPasswordGenerator\PasswordGenerator;

// append NYTimes feed to the specified wordlist, limiting to 7000 items max
$gen = new PasswordGenerator([
    'wordCacheFile'  => 'mywords.json',
    'url'            => 'https://rss.nytimes.com/services/xml/rss/nyt/World.xml',
    'minLength'      => 3,
    'maxLength'      => 8,
    'appendWordlist' => true,
    'limitWordlist'  => 7000,
]);



use \Darkv\PhpPasswordGenerator\PasswordGenerator;

$gen = PasswordGenerator::CACHED();

echo $gen->generate();



use \Darkv\PhpPasswordGenerator\PasswordGenerator;

// create instance with custom parameters
$gen = new PasswordGenerator([
    'url'           => 'https://www.some-url.com/source',
    'minLength'     => 3,
    'maxLength'     => 6,
    'httpRedirects' => 0,
]);
bash
composer