PHPackages                             pragmarx/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. pragmarx/recovery

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

pragmarx/recovery
=================

Create recovery codes for two factor auth

v0.2.1(4y ago)893.4M—8.6%13[2 issues](https://github.com/antonioribeiro/recovery/issues)[1 PRs](https://github.com/antonioribeiro/recovery/pulls)18MITPHPPHP &gt;=7.0

Since Sep 19Pushed 2y ago3 watchersCompare

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

READMEChangelog (1)Dependencies (4)Versions (4)Used By (18)

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

[](#recovery-codes)

[![Latest Stable Version](https://camo.githubusercontent.com/fbb52650b8b98efb210fe3ee04bf6435d8e858226a633fb6604615b29717a685/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f707261676d6172782f7265636f766572792e7376673f7374796c653d666c61742d737175617265267570646174653d313233)](https://packagist.org/packages/pragmarx/recovery)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/d3b46d722963893e3dbcafa936ef9e03373b2a99164f85ec494a16cc65758de1/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f6275696c642f672f616e746f6e696f7269626569726f2f7265636f766572792e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/antonioribeiro/recovery/build-status/master)[![Code Coverage](https://camo.githubusercontent.com/4ce948625c98bb6b9fd652dedc87cd8b515f0a841a05c76bb63ed24171a8d5b9/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f616e746f6e696f7269626569726f2f7265636f766572792e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/antonioribeiro/recovery/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/fd8e6116a4fbf3990fee0e189eb671a67e62c863682d5b869263f9684d11a447/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f616e746f6e696f7269626569726f2f7265636f766572792e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/antonioribeiro/recovery/?branch=master)[![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

41

—

FairBetter than 89% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity57

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.3% 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 ~713 days

Total

3

Last Release

1737d ago

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

v0.2.0PHP &gt;=7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/d9421a69d192db597169ec3519ad3efc6a35a660e4525e2ed08f6c753b908e86?d=identicon)[AntonioCarlosRibeiro](/maintainers/AntonioCarlosRibeiro)

---

Top Contributors

[![antonioribeiro](https://avatars.githubusercontent.com/u/3182864?v=4)](https://github.com/antonioribeiro "antonioribeiro (24 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

2falaravelphprecoveryrecovery-codestwo-factor-authenticationauth2fagoogle2fapragmarxbackup-codesrecoverytwo factor authaccount recoveryrecovery codes

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[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)[remotemerge/totp-php

Lightweight, fast, and secure TOTP (2FA) authentication library for PHP — battle tested, dependency free, and ready for enterprise integration.

2010.2k](/packages/remotemerge-totp-php)

PHPackages © 2026

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