PHPackages                             faaizz/pin\_generator - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. faaizz/pin\_generator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

faaizz/pin\_generator
=====================

A Laravel package to generate and emit PINs (personal identification numbers), suitable for use with cash cards, door locks, etc.

2.0.0(4y ago)01.1kMITPHP

Since May 11Pushed 4y ago1 watchersCompare

[ Source](https://github.com/Faaizz/pin_generator_package)[ Packagist](https://packagist.org/packages/faaizz/pin_generator)[ RSS](/packages/faaizz-pin-generator/feed)WikiDiscussions main Synced 5d ago

READMEChangelog (3)Dependencies (2)Versions (5)Used By (0)

PIN Generator Package for Laravel
=================================

[](#pin-generator-package-for-laravel)

A Laravel Package to generate cryptographically-secure pseudorandom PINs (personal identification numbers).

Target Features:

- Each PIN comprises four numeric digits (e.g. "2845")
- "Obvious" numbers should not be allowed (e.g. "1111", "1234")
- PINs should be generated in apparently random order
- A PIN should not be repeated until all preceding valid PINs have been emitted - even if the program is restarted between PINs.

Achieved Features:

- Each PIN comprises four numeric digits (e.g. "2845"): this is fulfilled by ensuring that each generated PIN is formatted as a 4-digit string.
- "Obvious" numbers should not be allowed (e.g. "1111", "1234"): this is satisfied by checking generated PINs against a pre-specified list of obvious numbers.
- PINs should be generated in apparently random order: this is satisfied by the usage of PHP's `random_int()` function (which generates cryptographically secure pseudo-random integers).
- A PIN should not be repeated until all preceding valid PINs have been emitted - This is ensured by making use of a Database. Whenever a new PIN is to be generated, the database is checked to see if all valid PINs have been generated. If yes, the database is reset. Otherwise, the database is checked for the newly generated PIN, if it already exists, the database is checked for preceding valid PINs. If all preceding valid PINs have been emitted, emit the generated PIN. Otherwise, a new PIN is generated and the check is performed over again.

Installation
------------

[](#installation)

To install PIN Generator package, run:

```
composer require faaizz/pin_generator
```

### Autoloading

[](#autoloading)

To automatically register the package with a Laravel project, the `PinGeneratorServiceProvider` can be added under `extra->laravel->providers` in `composer.json` as shown below:

```
...
"extra": {
    "laravel" : {
        "providers": [
            ...
            "Faaizz\\PinGenerator\\PinGeneratorServiceProvider"
            ...
        ]
    }
}
```

The service provider can also be manually registered in the Laravel project's `app/config/app.php` as:

```
