PHP code example of coreymcmahon / phpass

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

    

coreymcmahon / phpass example snippets



// Default configuration - bcrypt adapter, 2^12 (4,096) iterations
$phpassHash = new \PHPassLib\Hash;


// Customize hash adapter - PBKDF2 adapter, 15,000 iterations
$adapter = new \PHPassLib\Hash\Adapter\Pbkdf2(array (
    'iterationCount' => 15000
));
$phpassHash = new \PHPassLib\Hash($adapter);


// Create and verify a password hash from any of the above configurations
$passwordHash = $phpassHash->hashPassword($password);
if ($phpassHash->checkPassword($password, $passwordHash)) {
    // Password matches...
} else {
    // Password doesn't match...
}


// Default configuration (NIST recommendations)
$phpassStrength = new \PHPassLib\Strength;

// Returns 30
$passwordEntropy = $phpassStrength->calculate('MySecretPassword');


// Custom strength adapter (Wolfram algorithm)
$adapter = new \PHPassLib\Strength\Adapter\Wolfram;
$phpassStrength = new \PHPassLib\Strength($adapter);

// Returns 59
$passwordEntropy = $phpassStrength->calculate('MySecretPassword');
bash
    curl -sS https://getcomposer.org/installer | php
    
bash
    php composer.phar install