承接 kaiopiola/keygen 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

kaiopiola/keygen

最新稳定版本:1.2.5

Composer 安装命令:

composer require kaiopiola/keygen

包简介

Pattern-based key generator

README 文档

README

Essa documentação está disponível também em Português do Brasil.

If you find any bug, feel free to create a new issue!

The Keygen plugin is a key or serial generator based on user-defined mask patterns. The plugin is able to generate keys like the example below:

6W2F-4RJB-KV0Z-ADA6-4SJ2

It can be used to generate keys for several purposes, some examples are:

  • Unique links to reset passwords
  • Registration via invitation link
  • Two-Factor authentication codes
  • File sharing links
  • Product redemption keys
  • Discount coupons
  • Referral codes

Installation

Fisrt, run the following command in your project:

composer require kaiopiola/keygen

Then, call the main class on the PHP file you want to load it:

use Kaiopiola\Keygen\Key;

How Keygen works

How to create a new key

To create a new key, just instantiate the class in a variable, and then define its configuration parameters, as shown in the example below:

# Instantiating class in a variable:
$exampleKey = new Key;

# Setting parameters:
$exampleKey->setPattern("XXXX-NNNN-LLLL"); // Defines the pattern that the code will use to define its new key. 
// The letters represent the type of content that can be used in that space, as per the rule:
// X - Any letter or number
// N - Numbers only as defined
// L - Letters only as defined
// Any other characters like dashes, dots, slashes, and even other letters and numbers, will not be replaced.
// If this property is not defined, the following will be used by default: XXXXX-XXXXX-XXXXX

$exampleKey->setNumbers("789"); // Defines the numbers that can compose your key, if not defined, it will use by default "0123456789"
$exampleKey->setLetters("ABC"); // Defines the letters that can compose your key, if not defined, it will use by default "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

$exampleKey->generate(); // Generate your key and return a string value with the result

How to create a new unique key

You also have the option to generate an unique key to avoid duplicates, using the example below:

$exampleKey->setExistingKeys([]); // Defines the existing keys that the code will avoid duplicates. Must be type array.

$exampleKey->generateUnique(); // Generate your key and return a string value with the result

This is also compatible with setPattern, setNumbers and setLetters too!

Considerations

This project is open to contributions, whether with suggestions or improvements to the code of any kind. Feel free to participate in its development.

License

MIT License (MIT). Please, read the License File for more informations.

统计信息

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

GitHub 信息

  • Stars: 13
  • Watchers: 1
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-01-12