PHP code example of ifaqih / ifencryption

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

    

ifaqih / ifencryption example snippets


use IFaqih\IFEncryption\Password;

[
    [
        'algo'      =>  PASSWORD_BCRYPT,
        'options'   =>  [
            'cost'          =>  10
        ]
    ],
    [
        'algo'      =>  PASSWORD_ARGON2I,
        'options'   =>  [
            'time_cost'     =>  3,
            'memory_cost'   =>  128,
            'threads'       =>  1
        ]
    ],
    [
        'algo'      =>  PASSWORD_ARGON2ID,
        'options'   =>  [
            'time_cost'     =>  3,
            'memory_cost'   =>  128,
            'threads'       =>  1
        ]
    ]
]

class::set_algo()

class::set_rand_algo()

class::set_default_options()

class::set_options()

class::time_cost()

class::memory_cost()

class::threads()

class::cost()

class::hash()

class::verify()

class::new_hash()

class::get_details()

class::get_algo()

class::get_options()

use IFaqih\IFEncryption\Password;

$password = "@QweRty17@";

$hash = Password::set_algo(PASSWORD_BCRYPT)
    ->cost(10)
    ->hash($password);

$verify = Password::verify($password, $hash);

$new_hash = Password::new_hash();

$details = Password::get_details();

var_dump([
    "password"  =>  $password,
    "hash"      =>  $hash,
    "new_hash"  =>  $new_hash,
    "verify"    =>  $verify,
    "details"   =>  $details
]);

use IFaqih\IFEncryption\Password;

$password = "@QweRty17@";

$hash = Password::set_algo(PASSWORD_ARGON2ID)
    ->time_cost(7)
    ->memory_cost(512)
    ->threads(2)
    ->hash($password);

$verify = Password::verify($password, $hash);

$new_hash = Password::new_hash();

$details = Password::get_details();

var_dump([
    "password"  =>  $password,
    "hash"      =>  $hash,
    "new_hash"  =>  $new_hash,
    "verify"    =>  $verify,
    "details"   =>  $details
]);

use IFaqih\IFEncryption\Password;

$password = "@QweRty17@";

$hash = Password::set_algo(PASSWORD_ARGON2ID)
    ->set_options([
        'time_cost'     =>  11,
        'memory_cost'   =>  128,
        'threads'       =>  2
    ])
    ->hash($password);

$verify = Password::verify($password, $hash);

$new_hash = Password::new_hash();

$algo = Password::get_algo();

$options = Password::get_options();

var_dump([
    "password"  =>  $password,
    "hash"      =>  $hash,
    "new_hash"  =>  $new_hash,
    "verify"    =>  $verify,
    "algo"      =>  $algo,
    "options"   =>  $options
]);

use IFaqih\IFEncryption\Password;

$password = "@QweRty17@";

$hash = Password::set_rand_algo([
    [
        'algo'      =>  PASSWORD_BCRYPT,
        'options'   =>  [
            'cost'      =>  10
        ]
    ],
    [
        'algo'      =>  PASSWORD_ARGON2I,
        'options'   =>  [
            'time_cost'     =>  3,
            'memory_cost'   =>  128,
            'threads'       =>  1
        ]
    ],
    [
        'algo'      =>  PASSWORD_ARGON2ID,
        'options'   =>  [
            'time_cost'     =>  3,
            'memory_cost'   =>  128,
            'threads'       =>  1
        ]
    ]
])->hash($password);

var_dump([
    "password"  =>  $password,
    "hash"      =>  $hash,
    "verify"    =>  Password::verify($password, $hash),
    "new_hash"  =>  Password::new_hash(),
    "details"   =>  Password::get_details()
]);

return [
    [
        'algo'      =>  PASSWORD_BCRYPT,
        'options'   =>  [
            'cost'      =>  10
        ]
    ],
    [
        'algo'      =>  PASSWORD_ARGON2I,
        'options'   =>  [
            'time_cost'     =>  7,
            'memory_cost'   =>  512,
            'threads'       =>  2
        ]
    ],
    [
        'algo'      =>  PASSWORD_ARGON2ID,
        'options'   =>  [
            'time_cost'     =>  3,
            'memory_cost'   =>  128,
            'threads'       =>  1
        ]
    ]
];

use IFaqih\IFEncryption\Password;

$password = "@QweRty17@";

$hash = Password::set_algo(PASSWORD_ARGON2I)->hash($password);

var_dump([
    "password"  =>  $password,
    "hash"      =>  $hash,
    "verify"    =>  Password::verify($password, $hash),
    "new_hash"  =>  Password::new_hash(),
    "details"   =>  Password::get_details()
]);

return [
    [
        'algo'      =>  PASSWORD_BCRYPT,
        'options'   =>  [
            'cost'      =>  10
        ]
    ],
    [
        'algo'      =>  PASSWORD_ARGON2I,
        'options'   =>  [
            'time_cost'     =>  3,
            'memory_cost'   =>  512,
            'threads'       =>  1
        ]
    ],
    [
        'algo'      =>  PASSWORD_ARGON2ID,
        'options'   =>  [
            'time_cost'     =>  5,
            'memory_cost'   =>  128,
            'threads'       =>  2
        ]
    ]
];

use IFaqih\IFEncryption\Password;

$password = "@QweRty17@";

$hash = Password::hash($password);

echo "<pre>";
var_dump([
    "password"  =>  $password,
    "hash"      =>  $hash,
    "verify"    =>  Password::verify($password, $hash, REHASH_CONFIG),
    "new_hash"  =>  Password::new_hash(),
    "details"   =>  Password::get_details()
]);

return [
    [
        'algo'      =>  PASSWORD_BCRYPT,
        'options'   =>  [
            'cost'          =>  7
        ]
    ],
    [
        'algo'      =>  PASSWORD_ARGON2I,
        'options'   =>  [
            'time_cost'     =>  3,
            'memory_cost'   =>  128,
            'threads'       =>  1
        ]
    ],
    [
        'algo'      =>  PASSWORD_ARGON2ID,
        'options'   =>  [
            'time_cost'     =>  3,
            'memory_cost'   =>  128,
            'threads'       =>  1
        ]
    ]
];

use IFaqih\IFEncryption\Password;

$password = "@QweRty17@";

$hash = Password::set_default_options()->hash($password);

var_dump([
    "password"  =>  $password,
    "hash"      =>  [
        "hash"      =>  $hash,
        "verify"    =>  Password::verify($password, $hash, REHASH_CONFIG | REHASH_DEFAULT_OPTIONS),
        "details"   =>  Password::get_details()
    ],
    "new_hash"  =>  [
        "hash"      =>  Password::new_hash(),
        "verify"    =>  Password::verify($password, Password::new_hash(), DONT_REHASH),
        "details"   =>  Password::get_details()
    ]
]);

use IFaqih\IFEncryption\Password;

$password = "@QweRty17@";

$hash = Password::set_rand_algo([
    PASSWORD_BCRYPT,
    PASSWORD_ARGON2I,
    PASSWORD_ARGON2ID
])->set_default_options()->hash($password);

var_dump([
    "password"  =>  $password,
    "hash"      =>  [
        "hash"      =>  $hash,
        "verify"    =>  Password::verify($password, $hash, REHASH_RAND_ALL_ALGO | REHASH_DEFAULT_OPTIONS),
        "details"   =>  Password::get_details()
    ],
    "new_hash"  =>  [
        "hash"      =>  Password::new_hash(),
        "verify"    =>  Password::verify($password, Password::new_hash(), DONT_REHASH),
        "details"   =>  Password::get_details()
    ]
]);
bash
php artisan vendor:publish