rancoud / crypt
Crypt package
Requires
- php: ^8.4.27 || ^8.5.12 || ^8.6.0
- ext-mbstring: *
Requires (Dev)
- friendsofphp/php-cs-fixer: 3.95.1
- phpunit/phpunit: 12.5.22
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-master
- 4.0.4
- 4.0.3
- 4.0.2
- 4.0.1
- 4.0.0
- 3.3.2
- 3.3.1
- 3.3.0
- 3.2.10
- 3.2.9
- 3.2.8
- 3.2.7
- 3.2.6
- 3.2.5
- 3.2.4
- 3.2.3
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.0.0
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-chore/enhance-algo-check
- dev-chore/add-argon2-max-values
- dev-chore/php-composer
- dev-chore/add-sensitive-parameter-attribute
- dev-chore/ci-optimize
This package is auto-updated.
Last update: 2026-10-25 23:44:10 UTC
README
Crypt using Argon2id by default with Argon2i and bcrypt in fallback.
Installation
composer require rancoud/crypt
How to use it?
use Rancoud\Crypt\Crypt; $password = 'my_password'; $hash = Crypt::hash($password); $result = Crypt::verify($password, $hash); // use only Argon2i Crypt::useArgon2i(); // use only bcrypt Crypt::useBcrypt();
Crypt
Main functions
Hashes the password according to the selected algorithm.
public static function hash(#[\SensitiveParameter] string $password): string
Checks whether the hash needs to be rehash to match the selected algorithm and options.
public static function needsRehash(string $hash): bool
Checks if password and hash match.
public static function verify(#[\SensitiveParameter] string $password, string $hash): bool
Algorithms
Returns current algorithm.
Possible values are argon2id, argon2i or 2y.
public static function getCurrentAlgo(): string
Sets the algorithm to argon2id.
public static function useArgon2id(): void
Sets the algorithm to argon2i.
public static function useArgon2i(): void
Sets the algorithm to 2y (bcrypt).
public static function useBcrypt(): void
Options
Sets memory cost in KiB for argon2id and argon2i.
Must be between 8 and 1 048 576 and compatible with current threads.
public static function setOptionArgon2iMemoryCost(int $kib): void
Sets number of threads for argon2id and argon2i.
Must be between 1 and 64 and compatible with current memory cost.
public static function setOptionArgon2iThreads(int $threads): void
Sets time cost for argon2id and argon2i.
Must be between 1 and 10.
public static function setOptionArgon2iTimeCost(int $time): void
Sets rounds cost for 2y (bcrypt).
Must be between 4 and 31.
public static function setOptionBcryptCost(int $rounds): void
Returns options for argon2id and argon2i.
public static function getOptionsArgon2i(): array
Returns options for 2y (bcrypt).
public static function getOptionsBcrypt(): array
Random string
Returns a fixed-size string containing random characters from the preselection.
The default character pool is !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_``abcdefghijklmnopqrstuvwxyz{|}~.
public static function getRandomString(int $length = 64, ?string $characters = null): string
Returns the character pool.
public static function getCharactersForRandomString(): string
Sets the character pool.
public static function setCharactersForRandomString(string $characters): void
How to Dev
composer ci for php-cs-fixer and phpunit and coverage
composer lint for php-cs-fixer
composer test for phpunit and coverage