PHPackages                             rancoud/crypt - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. rancoud/crypt

ActiveLibrary[Testing &amp; Quality](/categories/testing)

rancoud/crypt
=============

Crypt package

4.0.1(2mo ago)09.8k↓25%2MITPHPPHP &gt;=8.4.0CI passing

Since Feb 4Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/rancoud/Crypt)[ Packagist](https://packagist.org/packages/rancoud/crypt)[ RSS](/packages/rancoud-crypt/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (34)Used By (0)

Crypt Package
=============

[](#crypt-package)

[![Packagist PHP Version Support](https://camo.githubusercontent.com/7a357f3805377a3a80e3362d46c6eb182be1c324ff7ec77703cae5494675e185/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f72616e636f75642f6372797074)](https://camo.githubusercontent.com/7a357f3805377a3a80e3362d46c6eb182be1c324ff7ec77703cae5494675e185/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f72616e636f75642f6372797074)[![Packagist Version](https://camo.githubusercontent.com/b8c7d613211ee46a4f96efe929fc4c0c8c41f7705c8dcdf9d58fabf16a3f8f25/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72616e636f75642f6372797074)](https://packagist.org/packages/rancoud/crypt)[![Packagist Downloads](https://camo.githubusercontent.com/c5e2a1f2606e922661bbec911fc61632224eb3b4ee3ce00f3f8f22c9dc9fb798/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72616e636f75642f6372797074)](https://packagist.org/packages/rancoud/crypt)[![Composer dependencies](https://camo.githubusercontent.com/aae95fbaa83bc6a3f4597f3a75da45ea46ec236fc324617f0e5a2f15e07fe750/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646570656e64656e636965732d302d627269676874677265656e)](https://github.com/rancoud/Crypt/blob/master/composer.json)[![Test workflow](https://camo.githubusercontent.com/e69c574ec514c1c2e828092a52f708a1ecb17d83e71f814de8f433edc0b9285c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f72616e636f75642f63727970742f746573742e796d6c3f6272616e63683d6d6173746572)](https://github.com/rancoud/crypt/actions/workflows/test.yml)[![Codecov](https://camo.githubusercontent.com/6ed1b2d920e5e9dece28b7add16962253bcb6545fde5bf98783febf4aa7f1748/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f72616e636f75642f63727970743f6c6f676f3d636f6465636f76)](https://codecov.io/gh/rancoud/crypt)

Crypt using Argon2id by default with Argon2i and bcrypt in fallback.

Installation
------------

[](#installation)

```
composer require rancoud/crypt
```

How to use it?
--------------

[](#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
-----

[](#crypt)

### Main functions

[](#main-functions)

Hashs the password according to the selected algorithm.

```
public static function hash(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(string $password, string $hash): bool
```

### Algorithms

[](#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

[](#options)

Sets memory cost for `argon2id` and `argon2i`.
Must be equal or greater than 8.

```
public static function setOptionArgon2iMemoryCost(int $bytes): void
```

Sets number of threads for `argon2id` and `argon2i`.
Must be equal or greater than 1.

```
public static function setOptionArgon2iThreads(int $threads): void
```

Sets time cost for `argon2id` and `argon2i`.
Must be equal or greater than 1.

```
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

[](#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
----------

[](#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

###  Health Score

59

—

FairBetter than 99% of packages

Maintenance89

Actively maintained with recent releases

Popularity26

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity92

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 76.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~95 days

Recently: every ~116 days

Total

32

Last Release

64d ago

Major Versions

1.0.5 → 2.0.02020-05-04

2.0.0 → 3.0.02020-05-09

3.3.2 → 4.0.02025-04-20

PHP version history (3 changes)1.0.0PHP &gt;=7.2.0

2.0.0PHP &gt;=7.4.0

4.0.0PHP &gt;=8.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/829a536bd4f71cadcd0266e272ccaf413e3fc9f2937248c9a2317ef0bf2d25ee?d=identicon)[rancoud](/maintainers/rancoud)

---

Top Contributors

[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (243 commits)")[![rancoud](https://avatars.githubusercontent.com/u/1884186?v=4)](https://github.com/rancoud "rancoud (76 commits)")

---

Tags

argon2iargon2idbcryptcomposercoveragecryptcryptographyhashpackagistphpphp84phpunit

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/rancoud-crypt/health.svg)

```
[![Health](https://phpackages.com/badges/rancoud-crypt/health.svg)](https://phpackages.com/packages/rancoud-crypt)
```

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[beberlei/assert

Thin assertion library for input validation in business models.

2.4k96.9M570](/packages/beberlei-assert)[mikey179/vfsstream

Virtual file system to mock the real file system in unit tests.

1.4k108.0M2.7k](/packages/mikey179-vfsstream)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)[phpspec/phpspec

Specification-oriented BDD framework for PHP 7.1+

1.9k36.7M3.1k](/packages/phpspec-phpspec)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
