https://github.com/rancoud/crypt
Crypt Package
https://github.com/rancoud/crypt
argon2i argon2id bcrypt composer coverage crypt cryptography hash packagist php php74 php8 php80 php81 phpunit phpunit9
Last synced: 3 months ago
JSON representation
Crypt Package
- Host: GitHub
- URL: https://github.com/rancoud/crypt
- Owner: rancoud
- License: mit
- Created: 2018-01-27T20:34:34.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2025-04-01T12:19:14.000Z (3 months ago)
- Last Synced: 2025-04-01T13:27:35.354Z (3 months ago)
- Topics: argon2i, argon2id, bcrypt, composer, coverage, crypt, cryptography, hash, packagist, php, php74, php8, php80, php81, phpunit, phpunit9
- Language: PHP
- Homepage: https://packagist.org/packages/rancoud/crypt
- Size: 457 KB
- Stars: 0
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
# Crypt Package

[](https://packagist.org/packages/rancoud/crypt)
[](https://packagist.org/packages/rancoud/crypt)
[](https://github.com/rancoud/Crypt/blob/master/composer.json)
[](https://github.com/rancoud/crypt/actions/workflows/test.yml)
[](https://codecov.io/gh/rancoud/crypt)Crypt using Argon2id by default with Argon2i and bcrypt in fallback.
## Installation
```php
composer require rancoud/crypt
```## How to use it?
```php
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
Hashs the password according to the selected algorithm.
```php
public static function hash(string $password): string
```Checks whether the hash needs to be rehash to match the selected algorithm and options.
```php
public static function needsRehash(string $hash): bool
```Checks if password and hash match.
```php
public static function verify(string $password, string $hash): bool
```### Algorithms
Returns current algorithm.
Possible values are `argon2id`, `argon2i` or `2y`.
```php
public static function getCurrentAlgo(): string
```Sets the algorithm to `argon2id`.
```php
public static function useArgon2id(): void
```Sets the algorithm to `argon2i`.
```php
public static function useArgon2i(): void
```Sets the algorithm to `2y` (bcrypt).
```php
public static function useBcrypt(): void
```### Options
Sets memory cost for `argon2id` and `argon2i`.
Must be equal or greater than 8.
```php
public static function setOptionArgon2iMemoryCost(int $bytes): void
```Sets number of threads for `argon2id` and `argon2i`.
Must be equal or greater than 1.
```php
public static function setOptionArgon2iThreads(int $threads): void
```Sets time cost for `argon2id` and `argon2i`.
Must be equal or greater than 1.
```php
public static function setOptionArgon2iTimeCost(int $time): void
```Sets rounds cost for `2y` (bcrypt).
Must be between 4 and 31.
```php
public static function setOptionBcryptCost(int $rounds): void
```Returns options for `argon2id` and `argon2i`.
```php
public static function getOptionsArgon2i(): array
```Returns options for `2y` (bcrypt).
```php
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{|}~`.
```php
public static function getRandomString(int $length = 64, ?string $characters = null): string
```Returns the character pool.
```php
public static function getCharactersForRandomString(): string
```Sets the character pool.
```php
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