faaizz/pin_generator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

faaizz/pin_generator

最新稳定版本:2.0.0

Composer 安装命令:

composer require faaizz/pin_generator

包简介

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

README 文档

README

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

To install PIN Generator package, run:

composer require faaizz/pin_generator

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:

<?php
...
'providers' => [
    ...
    Faaizz\PinGenerator\PinGeneratorServiceProvider::class
],
...

Migration

The database migrations can be run by executing database migration in the Laravel project:

php artisan migrate

Facade

The Generator facade can be used from the Faaizz\PinGenerator\Facades namespace after the PinGeneratorServiceProvider has been registered with a Laravel project.

Usage

Easily generate PINs by calling the generatePin() method on the Generator facade:

use Faaizz\PinGenerator\Facades\Generator;
...
$pin = Generator::generatePin();

Configuration

Publish

To publish package configs into a Laravel project, run:

php artisan vendor:publish --provider="Faaizz\PinGenerator\PinGeneratorServiceProvider" --tag="config"

This publishes the config into app/config/pingenerator.php.

Customization

To configure the package, edit app/config/pingenerator.php in Laravel project appropriately.

  • Change number of digits: To change the number of digits of generated PINs, map the desired value to the digit key. For example, to generate 10-digit PINs:
// config/config.php
return [
    'digits' => 10
    ...
];
  • Add/Remove Obvious Number: To add/remove "obvious" numbers, edit the mapped value of obvious_numbers as required:
// config/config.php
return [
    ...
    'obvious_numbers' => [
        0000, 1111, 2222, 3333, 4444, 5555, 6666, 7777,
        8888, 9999, 1234, 5678, 1010, 2020
    ]
];

Testing

Run tests by executing:

# Note: composer install must have been run to install dependencies
./execTests.sh

References

统计信息

  • 总下载量: 1.13k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-05-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固