Download the PHP package ifaqih/ifencryption without Composer
On this page you can find all versions of the php package ifaqih/ifencryption. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package ifencryption
IFEncryption
IFEncryption is a simple library that serves to disguise the algorithm method along with options from the password_hash function in php.
PHP Version: 8.0 or above |-
Installation
With Composer:
Use The Library
Configuration
Configuration is useful for setting the default algorithm to be used and its options.
You can set the configuration in the if-encryption.php file in the config directory.
Publish Configuration
In laravel you can also publish configuration file by doing php artisan command
then select IFaqih\IFEncryption\ServiceProvider
Configuration Array Format
Constants
All the constants used by this library.
PHP Default Constants
Existing constants from php:
Constant Name | Value | Description |
---|---|---|
PASSWORD_BCRYPT |
"2y" |
Use the CRYPT_BLOWFISH algorithm to create the hash |
PASSWORD_ARGON2I |
"argon2i" |
Use the Argon2i hashing algorithm to create the hash. This algorithm is only available if PHP has been compiled with Argon2 support |
PASSWORD_ARGON2ID |
"argon2id" |
Use the Argon2id hashing algorithm to create the hash. This algorithm is only available if PHP has been compiled with Argon2 support |
PASSWORD_BCRYPT_DEFAULT_COST |
10 |
Default cost set by php |
PASSWORD_ARGON2_DEFAULT_MEMORY_COST |
65536 |
Default memory cost set by php |
PASSWORD_ARGON2_DEFAULT_TIME_COST |
4 |
Default time cost set by php |
PASSWORD_ARGON2_DEFAULT_THREADS |
1 |
Default threads set by php |
Constants Added By The Library
Additional constants to support this library:
Constant Name | Value | Description |
---|---|---|
DONT_REHASH |
1 |
Rehashing will not be performed |
REHASH_FIXED |
2 |
Will perform rehashing based on available hashes |
REHASH_CONFIG |
4 |
Will perform rehashing based on the configuration that has been set |
REHASH_BCRYPT |
8 |
Will perform rehashing using the CRYPT_BLOWFISH algorithm |
REHASH_ARGON2I |
16 |
Will perform rehashing using the Argon2i algorithm |
REHASH_ARGON2ID |
32 |
Will perform rehashing using the Argon2id algorithm |
REHASH_RAND_ALL_ALGO |
64 |
Will perform the rehashing using one of all randomly selected algorithms |
REHASH_DEFAULT_OPTIONS |
128 |
Will do rehashing with default options from php |
Class Methods
Set Algorithm
Set of algorithms to be used.
- Type:
static
- Parameter data type:
string $algo
- Return data type:
object
Set Random Algorithm
Which set of algorithms will be used, which will be randomly selected by the library.
- Type:
static
- Parameter data type:
array $algo
- Return data type:
object
Set Default Options
Set to the default options set by php.
- Type:
static
- Parameter data type: no parameter
- Return data type:
object
Set Options
Set options of algorithms to be used.
- Type:
non-static
- Parameter data type:
array $options
- Return data type:
object
Set Time Cost
Set time cost of algorithms to be used.
- Type:
non-static
- Parameter data type:
int $time_cost
- Return data type:
object
this class method only applies if you use ARGON2I and ARGON2ID algorithms
Set Memory Cost
Set memory cost of algorithms to be used.
- Type:
non-static
- Parameter data type:
int $memory_cost
- Return data type:
object
this class method only applies if you use ARGON2I and ARGON2ID algorithms
Set Threads
Set threads of algorithms to be used.
- Type:
non-static
- Parameter data type:
int $threads
- Return data type:
object
this class method only applies if you use ARGON2I and ARGON2ID algorithms
Set Cost
Set cost of bcrypt to be used.
- Type:
non-static
- Parameter data type:
int $cost
- Return data type:
object
this class method only applies if you use the BCRYPT algorithm
Execute Hashing
Executes hashing according to predefined algorithms and options.
- Type:
static
- Parameter data type:
string $str
- Return data type:
string|false
Verify Hash
Verify string with existing hash.
- Type:
static
- Parameter data type:
string $str, string $existingHash, int $rehash_flag = REHASH_FIXED
- Return data type:
bool
additional constants are useful as rehash flags in the verify() method
Get New Hash
Get the new hash after verify.
- Type:
static
- Parameter data type: no parameter
- Return data type:
string|null
Get Details Hash
Get details of hash data.
- Type:
static
- Parameter data type: no parameter
- Return data type:
object
Get Algorithm Data
Get the algorithm data used.
- Type:
static
- Parameter data type: no parameter
- Return data type:
object
Get Option Data
Get the data of the options used.
- Type:
static
- Parameter data type: no parameter
- Return data type:
object
Example
Example 1:
-
bcrypt example:
-
bcrypt example result:
-
argon2 example:
- argon2 example result:
Example 2:
-
example:
- result:
Example 3:
Example with set_rand_algo() method
-
example:
- result:
Example 4:
Example with config file and set_algo() method
-
config file:
-
exmaple:
- result:
Example 5:
In this example if there is more than one algorithm in the config array, it will be chosen randomly by the library.
-
config file:
-
exmaple:
- result:
Example 6:
In this example the library will only apply the algorithm in the configuration file while the options will be overridden by the default options from php.
-
config file:
-
example:
- result:
Example 7:
Example by using the set_rand_algo() and set_default_options() methods.
-
example:
- result: