PHP code example of germania-kg / hash

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

    

germania-kg / hash example snippets



use Germania\Hash\PasswordHashCallable;

// Create Callable, optional with PSR-3 Logger
$hashing = new PasswordHashCallable;
$hashing = new PasswordHashCallable( $monolog );

// Get hashed value
echo $hashing( "mysecret" );


use Germania\Hash\PasswordHashCallable;

// Defaults
PasswordHashCallable::$cost = 14;
PasswordHashCallable::$algo = \PASSWORD_BCRYPT;


use Germania\Hash\PasswordVerifyCallable;

// Create Callable, optional with PSR-3 Logger
$verifier = new PasswordVerifyCallable;
$verifier = new PasswordVerifyCallable( $monolog );

// Get hashed value
$secret = "foobar";
$hash   = password_hash($secret, \PASSWORD_BCRYPT);
$hash   = password_hash($secret, \PASSWORD_DEFAULT)

// Will be TRUE
echo $verifier( "foobar", $hash );

// Will be FALSE
echo $verifier( "wrong", $hash );


use Germania\Hash\CallbackHashCallable;

// Create anonymous function
$callback = function( $token ) {
	return password_hash( $token );
};

// Create Callable, optional with PSR-3 Logger
$hashing = new CallbackHashCallable( $callback );
$hashing = new CallbackHashCallable( $callback, $monolog );

// Get hashed value
echo $hashing( "mysecret" );