PHP code example of createnl / zxcvbn-bundle

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

    

createnl / zxcvbn-bundle example snippets


use Createnl\ZxcvbnBundle\ZxcvbnFactoryInterface;

class PasswordController
{
    public function updatePassword(string $password, ZxcvbnFactoryInterface $zxcvbnFactory)
    {
        $userData = [
          'Marco',
          '[email protected]'
        ];

        $zxcvbn = $zxcvbnFactory->createZxcvbn();

        $weak = $zxcvbn->passwordStrength($password, $userData);
        echo $weak['score']; // will print 0
        
        $strong = $zxcvbn->passwordStrength('correct horse battery staple');
        echo $strong['score']; // will print 4

        echo $weak['feedback']['warning']; // will print user-facing feedback on the password, set only when score <= 2
        echo $weak['feedback']['suggestions']; // may contain user-facing suggestions to improve the score
    }
}