creativecrafts / laravel-secure-random-number-generator
A handy package to generate a secure unique random number for a model
1.0.0
2024-03-17 06:22 UTC
Requires
- php: ^8.2
- illuminate/contracts: ^11.0|^10.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1|^7.0
- orchestra/testbench: ^9.0|^8.5
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
This package is auto-updated.
Last update: 2024-10-08 15:24:54 UTC
README
A handy package to generate a secure unique random number for a model.
Installation
You can install the package via composer:
composer require creativecrafts/laravel-secure-random-number-generator
You can publish the config file with:
php artisan vendor:publish --tag="secure-random-number-generator-config"
This is the contents of the published config file:
return [ /* |-------------------------------------------------------------------------- | Default Number Range |-------------------------------------------------------------------------- | | This option controls the default number range that will be used | when generating a random number. | */ 'from_number_range' => 1, 'to_number_range' => 9999999, ];
Usage
use CreativeCrafts\SecureRandomNumberGenerator\SecureRandomNumberGenerator; // Generate a random unique number for a model // To make the number unique for a model, the package uses the model's table name and column name to check if the number is unique in the model's table // The from and to number range can be empty and the package will use the default number range set in the configuration file $tableName = 'users' $tableColumn = 'registration_number'; $fromNumberRange = 100; $toNumberRange = 9999999; $secureUniqueRandomNumber = SecureRandomNumberGenerator::forModel($fromNumberRange, $toNumberRange, $tableName, $tableColumn,)->generate(); // Generate a random number with a default value set in the configuration file $secureRandomNumber = SecureRandomNumberGenerator::useDefaultConfigNumberRange()->generate(); // Generate a random number with a custom number range $fromNumberRange = 100; $toNumberRange = 9999999; $secureRandomNumber = SecureRandomNumberGenerator::setNumberRange($fromNumberRange, $toNumberRange)->generate(); // Generate a random unique number for a model using the default number range set in the configuration file $tableName = 'users' $tableColumn = 'registration_number'; $secureUniqueRandomNumber = SecureRandomNumberGenerator::forModelUsingDefaultConfigNumberRange($tableName, $tableColumn)->generate();
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.