/keygen-package

Gerador de chaves com padrões de caracteres

Primary LanguagePHPMIT LicenseMIT

Keygen

en-US

This plugin is under development and may exhibit unexpected behavior while using it, please report any bugs or errors you find when using this solution, so that we can make it the best possible for your use!

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

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

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.


pt-BR

Este plugin está em desenvolvimento e pode apresentar comportamento inesperado durante o seu uso, por favor, reporte qualquer tipo de bug ou erro que encontrar ao utilizar essa solução, para que possamos torná-la a melhor possível para o seu uso!

O plugin Keygen é um gerador de chaves ou seriais baseado em padrões de máscara definidos pelo usuário. O plugin é capaz de gerar chaves como o exemplo abaixo:

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

Pode ser utilizado para gerar chaves em diversas finalidades, são alguns exemplos:

  • Links únicos para redefinição de senhas
  • Cadastros via link de convite
  • Códigos de autenticação de dois fatores
  • Links de compartilhamento de arquivos
  • Chaves de resgate de produtos
  • Cupons de desconto

Instalação

Primeiro, execute o seguinte comando em seu projeto:

composer require kaiopiola/keygen

Então, chame a classe principal no arquivo PHP onde deseja utiliza-la:

use Kaiopiola\Keygen\Key;

Como o Keygen funciona

Como criar uma nova chave

Para criar uma nova chave, basta instanciar a classe em uma variável, e em seguida, definir seus parâmetros de configurações, conforme exemplo abaixo:

# Instanciando classe em uma variável:
$chave = new Key;

# Definindo parâmetros:
$chave->setPattern("XXXX-NNNN-LLLL"); // Define o padrão que o código utilizará para definir sua nova chave. 
// As letras representam o tipo de conteúdo que pode ser usado naquele espaço, conforme a regra:
// X - Qualquer letra ou número
// N - Apenas números, conforme definido
// L - Apenas letras, conforme definido
// Quaisquer outros caracteres como traços, pontos, barras, e até mesmo outras letras e números, não serão substituídos.
// Caso essa propriedade não esteja definida, será utilizada por padrão a seguinte: XXXXX-XXXXX-XXXXX

$chave->setNumbers("789"); // Define os números que poderão compor sua chave, se não definido, irá utilizar por padrão "0123456789"
$chave->setLetters("ABC"); // Define as letras que poderão compor sua chave, se não definido, irá utilizar por padrão "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

$chave->generate(); // Gera sua chave e retorna um valor do tipo string com o resultado

Considerações

Este projeto é aberto à contribuições, sejam com sugestões e ou melhorias no código de qualquer tipo. Sinta-se à vontade para participar do seu desenvolvimento.

Licença

Licença MIT (MIT). Por favor, leia o Arquivo de Licença para maiores informações.