Create recovery codes for two factor auth

v2.2.0 2022-03-31 05:55 UTC

This package is auto-updated.

Last update: 2022-07-31 00:25:20 UTC


Latest Stable Version Software License StyleCI

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


Via Composer

$ composer require pragmarx/recovery


Basic array usage

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



If you are using Laravel or install a package like Collect, you can:


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



Json result


Should give you


Changing the result values/sizes

     ->setCount(8)     // Generate 8 codes
     ->setBlocks(5)    // Every code must have 7 blocks
     ->setChars(16)    // Each block must have 16 chars

Should give you


Numeric or alpha?

     ->numeric()       // Generate numeric only codes
     ->alpha()        // Get back to default alpha generation

Upper, lower and mixed case

     ->lowercase()    // All lower
     ->uppercase()    // All upper
     ->mixedcase()    // Get back to default mixed case

Block separator

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


Change log

Please see CHANGELOG for more information on what has changed recently.


$ composer update
$ vendor/bin/phpunit


Please see CONTRIBUTING for details.


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



The MIT License (MIT). Please see License File for more information.