aldemco / secrets
The package implements the functionality of creating, storing, checking secrets
Requires
- php: ^8.0
- illuminate/contracts: ^9.30|^10.0|^11.0|^12.0|^13.0
- spatie/laravel-package-tools: ^1.9.2
Requires (Dev)
- laravel/pint: ^1.0
- nesbot/carbon: ^2.63|^3.0
- nunomaduro/collision: ^6.0|^7.0|^8.0
- nunomaduro/larastan: ^2.0.1|^3.0
- orchestra/testbench: ^7.6|^8.0|^9.0|^10.0|^11.0
- pestphp/pest: ^1.22|^2.34|^3.8
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.8|^2.0
- phpstan/phpstan-deprecation-rules: ^1.0|^2.0
- phpstan/phpstan-phpunit: ^1.0|^2.0
- phpunit/phpunit: ^9.5|^10.5|^11.5
- spatie/laravel-ray: ^1.26
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-16 09:16:05 UTC
README
This package allows you to generate, store and verify secrets for many purposes, such as verifying a phone number during registration or authorization via SMS.
Installation
You can install the package via composer:
composer require aldemco/secrets
You can publish and run the migrations with:
php artisan vendor:publish --tag="secrets-migrations"
php artisan migrate
if you want to change the default table name, then publish the config first
You can publish the config file with:
php artisan vendor:publish --tag="secrets-config"
This is the contents of the published config file:
return [ 'table' => 'secrets', 'auto_clearing' => false, 'auto_clearing_dayly_at' => '01:00', 'length' => 6, 'secret_generator' => Aldemco\Secrets\SecretGenerator::class, 'secret_hasher' => Aldemco\Secrets\SecretHasher::class, 'is_crypt' => false, 'attemps' => 3, 'store_until_minutes' => 50000, 'valid_until_minutes' => 10, 'valid_from_minutes' => 0, 'multiple_limit' => 10, ];
Basic usage
Create secret
use Aldemco\Secrets\Secrets; /** * Full */ Secrets::create( context:'Verify', contextId: null, owner: 'User', ownerId: 1 ) ->length(6) ->setStoreUntil(Carbon\Carbon::now()->addDay(1)) ->setValidUntil(Carbon\Carbon::now()->addMinutes(10)) ->setAttemps(5) ->withInterval(60) ->genSecretStr(new Aldemco\Secrets\SecretGenerator) ->genCustomSecret(function(){ return \Str::UUID()->toString(); }) ->encrypt(new Aldemco\Secrets\SecretHasher) ->save(); /** * Minimal */ Secrets::create()->save();
Verify secret
use Aldemco\Secrets\Secrets; /** * Full */ Secrets::check( inputSecret: '112544', context:'Verify', owner: 'User', ownerId: 1) ->setEncrypt(new Aldemco\Secrets\SecretHasher) ->setUnlimitedAttemps() ->allowMultiple() ->setDissalowSuccessTimestamp() ->setUnlimitedAttemps() ->removeOnSuccess() ->verify() ->getResult(); /** * Minimal */ Secrets::check(inputSecret: '112544')->verify();
Commands
select: all used unactive withoutAttemps expired
php artisan secrets:clear {select} {context?}
Installation
You can install the package via composer:
composer require aldemco/secrets
Testing
composer test
Testing and debugging with Docker Compose
Run the test suite against a specific Laravel version (9, 10, 11, 12 or 13):
LARAVEL_VERSION=11 docker compose run --rm tests
The default version is Laravel 13. The container installs the matching Laravel framework and Orchestra Testbench version, then runs Pest. The project directory is mounted into the container, so code changes are immediately available.
For interactive debugging, start a shell instead of the test runner:
docker compose run --rm --entrypoint bash tests -l
Xdebug is enabled in the container and connects to the host on port 9003. To run
the test suite from the shell with a debugger attached, set XDEBUG_TRIGGER=1:
XDEBUG_TRIGGER=1 vendor/bin/pest
Set XDEBUG_MODE=off when you want to run tests without the debugger:
XDEBUG_MODE=off LARAVEL_VERSION=12 docker compose run --rm tests
License
The MIT License (MIT). Please see License File for more information.