PHP code example of eureka / component-password

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

    

eureka / component-password example snippets




use Eureka\Component\Password\PasswordGenerator;
use Eureka\Component\Password\StringGenerator;

//~ Use service generator
$length  = 16;  // default
$alpha   = 0.6; // default
$numeric = 0.2; // default
$special = 0.2; // default

$generator = new PasswordGenerator(
    new StringGenerator()
);

$password = $generator->generate($length, $alpha, $numeric, $special);

echo $password->getPlain() . PHP_EOL;
echo $password->getHash() . PHP_EOL;



use Eureka\Component\Password\Password;

//~ Just define password
$password = new Password('mySecretPassword');

echo $password->getHash() . PHP_EOL;
echo $password->getPlain() . PHP_EOL;




use Eureka\Component\Password\PasswordChecker;

//~ Just define password
$passwordChecker = new PasswordChecker();

$passwordPlain = 'mypassword'; // From login form 
$passwordHash  = '...';        // Retrieved from db for example
echo 'Is valid password: ' . $passwordChecker->verify($passwordPlain, $passwordHash) . PHP_EOL;