PHP code example of ronald-ph / strong-pass

1. Go to this page and download the library: Download ronald-ph/strong-pass 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/ */

    

ronald-ph / strong-pass example snippets


$checker = new RonaldPh\StrongPass\PasswordChecker();
$result = $checker->inspect($password);

use RonaldPh\StrongPass\PasswordChecker;

$checker = new PasswordChecker();
$result = $checker->inspect($_POST['password'] ?? '');

if ($result->failed()) {
    echo htmlspecialchars($result->message(), ENT_QUOTES, 'UTF-8');
}

$checker = new PasswordChecker([
    'standard' => 'basic',
    'context' => ['words' => ['your-company-name']],
    'blocklist' => [
        'config' => ['words' => ['project-name']],
    ],
]);

use RonaldPh\StrongPass\Facades\StrongPass;

public function register(Request $request)
{
    StrongPass::check($request);

    // Only reached when the password passed.
    $user = User::create($request->all());

    return redirect()->route('dashboard');
}

$result = StrongPass::check($request);   // only returns if it passed
$result->score;

StrongPass::check($request);   // password only, no password_confirmation

$request->validate([
    'email'    => ['d', new StrongPasswordRule],
]);

$result = StrongPass::inspect('correct horse battery staple');

$result->passed();       // bool
$result->score;          // 0-4
$result->entropy;        // estimated bits
$result->feedback;       // array of suggestions
$result->blockedBy;      // 'config', 'pwned', or null
$result->standard;       // which standard judged it

config()->set('strong-pass.standard', 'pci');

'fields' => [
    'password'     => 'new_password',
    'confirmation' => 'new_password_confirmation',
],

'blocklist' => [
    'drivers' => ['config'],
    'config'  => [
        'use_builtin' => true,
        'words'       => ['yourcompany', 'yourdomain'],
    'match'       => 'exact',  // or 'contains'; also catches "Password123!" and "P@ssw0rd"
    ],
],

'blocklist' => [
    'drivers' => ['config', 'pwned'],
    'pwned'   => [
        'enabled'   => true,
        'fail_open' => true,   // see below
        'cache_ttl' => 86400,
        'timeout'   => 3,
    ],
],

'context' => [
    'use_authenticated_user' => true,
    'words'                  => ['acme', 'springfield'],
],
bash
php artisan strong-pass:fetch-blocklist