PHPackages                             jc5/recovery - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. jc5/recovery

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

jc5/recovery
============

Create recovery codes for two factor auth

v2.2.0(4y ago)062.3k↑28.2%1MITPHPPHP &gt;=8.0

Since Sep 19Pushed 4y agoCompare

[ Source](https://github.com/JC5/recovery)[ Packagist](https://packagist.org/packages/jc5/recovery)[ Docs](https://github.com/JC5/recovery)[ RSS](/packages/jc5-recovery/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (6)Used By (1)

Recovery Codes
==============

[](#recovery-codes)

[![Latest Stable Version](https://camo.githubusercontent.com/f928a479e21f7bca766d94d6d1571514e5366697bc4c8008bd3a0711021a4b4d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a63352f7265636f766572792e7376673f7374796c653d666c61742d737175617265267570646174653d313233)](https://packagist.org/packages/pragmarx/recovery)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![StyleCI](https://camo.githubusercontent.com/0d3537ac5babfe04c5bf410c0877b36701cc8fca8c74b04f0ac4f56f3b5d1ef9/68747470733a2f2f7374796c6563692e696f2f7265706f732f3130333536383231392f736869656c64)](https://styleci.io/repos/103568219)

Generate recovery/backup codes to provide a way for your users to recover from a lost two factor auth, or any problem with it.

Install
-------

[](#install)

Via Composer

```
$ composer require pragmarx/recovery
```

Usage
-----

[](#usage)

#### Basic array usage

[](#basic-array-usage)

```
$this->recovery = new PragmaRX\Recovery();

$this->recovery->toArray();
```

#### Collection

[](#collection)

If you are using Laravel or install a package like [Collect](https://github.com/tightenco/collect), you can:

```
$this->recovery->toCollection();
```

You can also define a different collection function to be used:

```
$this->recovery->collectionFunction('alternateCollection');

$this->recovery->setCount(8)->toCollection();
```

#### Json result

[](#json-result)

```
$this->recovery->toJson();
```

Should give you

```
[
   "C0r2Xp4o1v-oG3pteKXw3",
   "oLuSmVeJ7D-t4wnJVwkuC",
   "XdPXXJy3J6-Gl3d0EwWt7",
   "Bn8twjUJRt-Lv3KaAFwjR",
   "SrnMagyGRg-eC7WPyFQ17",
   "mRO4WPJpRN-hgfrUZqqZd",
   "xBZtyFOrJZ-Tbpg0pSvzf",
   "eiPFmwvJp0-oSqdNKclDH"
]
```

#### Changing the result values/sizes

[](#changing-the-result-valuessizes)

```
$this->recovery
     ->setCount(8)     // Generate 8 codes
     ->setBlocks(5)    // Every code must have 7 blocks
     ->setChars(16)    // Each block must have 16 chars
     ->toArray();
```

Should give you

```
[
   "0ldZb4vhamHEd8B3-Tmri54Lb0t52wefR-gbJaHTN44O9C1igf-HRdF185SXxDwcdRf",
   "sFyrtezhjbFhCube-MszCKzvdsNL7QEY1-IY5OtpsFqM5d7jA7-t2mjCViRMHcMDdNZ",
   "bjKMlcsPhNrpFpSN-IbJR2ebOeXCxXVVb-omZLu3Ki9ImIEqZh-1sK74zOADl86GGRs",
   "wpa23eFj8PJcPdMG-E8A4LCwmd8iF8jt4-bVi2ltUEv29zoPJJ-pSetq2GD6euvZ9RA",
   "EJ3SRDQlddr2e2hT-eF79n1lqndwhRM7G-HrjHEVyA9zHSLi8g-TrHzl5oaqPi1NgCT",
   "lL7p4zjFxhQLND24-MEV1lmmyEKObjhhT-ldRWbOEnJLjBHmuc-Iex10bYAZ3NBljo2",
   "uomVxkrjGYqOqmdm-AtI9MiqFEJjTlSRi-AUNEwwUfrJVP5iaH-uyrsFCrqzC3WcaAa"
]
```

#### Numeric or alpha?

[](#numeric-or-alpha)

```
$this->recovery
     ->numeric()       // Generate numeric only codes
     ->toArray();

$this->recovery
     ->alpha()        // Get back to default alpha generation
     ->toArray();
```

#### Upper, lower and mixed case

[](#upper-lower-and-mixed-case)

```
$this->recovery
     ->lowercase()    // All lower
     ->toArray();

$this->recovery
     ->uppercase()    // All upper
     ->toArray();

$this->recovery
     ->mixedcase()    // Get back to default mixed case
     ->toArray();
```

#### Block separator

[](#block-separator)

Usually `-` is used as a block separator, but you can change it with:

```
$this->recovery->setBlockSeparator('|')->toJson();
```

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
$ composer update
$ vendor/bin/phpunit
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Antonio Carlos Ribeiro](https://github.com/antonioribeiro)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 68.6% 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 ~413 days

Total

5

Last Release

1510d ago

Major Versions

v0.1.0 → v2.0.02020-12-17

PHP version history (3 changes)v0.1.0PHP ~7.0

v2.0.0PHP ^7.4|^8.0

v2.0.1PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/48108cc08b6a55e32067a7344558f8fd3169797407b7ebc28b16b82e726c3638?d=identicon)[TheGrumpyDictator](/maintainers/TheGrumpyDictator)

---

Top Contributors

[![antonioribeiro](https://avatars.githubusercontent.com/u/3182864?v=4)](https://github.com/antonioribeiro "antonioribeiro (24 commits)")[![JC5](https://avatars.githubusercontent.com/u/5889984?v=4)](https://github.com/JC5 "JC5 (9 commits)")[![mattdemarillac](https://avatars.githubusercontent.com/u/53460562?v=4)](https://github.com/mattdemarillac "mattdemarillac (1 commits)")[![wells](https://avatars.githubusercontent.com/u/2041871?v=4)](https://github.com/wells "wells (1 commits)")

---

Tags

auth2fagoogle2fapragmarxbackup-codesrecoverytwo factor authaccount recoveryrecovery codes

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/jc5-recovery/health.svg)

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

###  Alternatives

[pragmarx/recovery

Create recovery codes for two factor auth

893.4M19](/packages/pragmarx-recovery)[pragmarx/google2fa

A One Time Password Authentication package, compatible with Google Authenticator.

2.0k82.4M164](/packages/pragmarx-google2fa)[pragmarx/google2fa-qrcode

QR Code package for Google2FA

12124.6M37](/packages/pragmarx-google2fa-qrcode)[ellaisys/aws-cognito

AWS Cognito package that allows Auth and other related features using the AWS SDK for PHP

120220.7k1](/packages/ellaisys-aws-cognito)[scheb/2fa-backup-code

Extends scheb/2fa-bundle with backup codes support

183.6M20](/packages/scheb-2fa-backup-code)[chillerlan/php-authenticator

A generator for counter- and time based 2-factor authentication codes (Google Authenticator). PHP 8.2+

58119.1k2](/packages/chillerlan-php-authenticator)

PHPackages © 2026

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