pragmarx / recovery
Create recovery codes for two factor auth
Installs: 2 093 008
Dependents: 16
Suggesters: 13
Security: 0
Stars: 86
Watchers: 4
Forks: 11
Open Issues: 1
Requires
- php: >=7.0
- pragmarx/random: ~0.1
Requires (Dev)
- phpunit/phpunit: >=5.4.3
- squizlabs/php_codesniffer: ^2.3
- tightenco/collect: ^5.0
Suggests
- tightenco/collect: Allows to generate recovery codes as collections
This package is auto-updated.
Last update: 2024-11-15 19:50:35 UTC
README
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
Via Composer
$ composer require pragmarx/recovery
Usage
Basic array usage
$this->recovery = new PragmaRX\Recovery(); $this->recovery->toArray();
Collection
If you are using Laravel or install a package like 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
$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
$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?
$this->recovery ->numeric() // Generate numeric only codes ->toArray(); $this->recovery ->alpha() // Get back to default alpha generation ->toArray();
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
Usually -
is used as a block separator, but you can change it with:
$this->recovery->setBlockSeparator('|')->toJson();
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
$ composer update $ vendor/bin/phpunit
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email acr@antoniocarlosribeiro.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.