kaiopiola / keygen
基于模式的密钥生成器
1.2.5
2022-05-24 01:38 UTC
Requires
- php: ^7.4|^8.0
Requires (Dev)
- phpunit/phpunit: ^9.5
README
此文档还可用作巴西葡萄牙语。
如果您发现任何错误,请随时创建新问题!
Keygen 插件是一种基于用户定义的掩码模式的密钥或序列号生成器。该插件可以生成如下示例中的密钥
6W2F-4RJB-KV0Z-ADA6-4SJ2
它可以用于生成多种目的的密钥,以下是一些示例
- 重置密码的唯一链接
- 通过邀请链接注册
- 双因素认证代码
- 文件共享链接
- 产品兑换密钥
- 折扣券
- 推荐代码
安装
首先,在您的项目中运行以下命令
composer require kaiopiola/keygen
然后,在您想要加载的 PHP 文件中调用主类
use Kaiopiola\Keygen\Key;
Keygen 的工作原理
如何创建新密钥
要创建新密钥,只需在变量中实例化类,然后定义其配置参数,如下所示
# 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
如何创建唯一密钥
您还可以使用以下示例生成唯一密钥以避免重复
$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
这也与 setPattern、setNumbers 和 setLetters 兼容!
注意事项
该项目接受任何形式的贡献,无论是建议还是对代码的任何改进。请自由参与其开发。
许可证
MIT 许可证(MIT)。请参阅许可证文件获取更多信息。