28 lines
651 B
PHP
Executable File
28 lines
651 B
PHP
Executable File
<?php
|
|
|
|
namespace Modules\Licensing\Services;
|
|
|
|
final class LicenseKey
|
|
{
|
|
public static function generate(): string
|
|
{
|
|
$alphabet = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
|
|
$raw = '';
|
|
for ($i = 0; $i < 20; $i++) {
|
|
$raw .= $alphabet[random_int(0, strlen($alphabet) - 1)];
|
|
}
|
|
|
|
return implode('-', str_split($raw, 5));
|
|
}
|
|
|
|
public static function normalize(string $value): string
|
|
{
|
|
return strtoupper(preg_replace('/[^A-Z0-9]/i', '', trim($value)) ?? '');
|
|
}
|
|
|
|
public static function hash(string $value): string
|
|
{
|
|
return hash('sha256', self::normalize($value));
|
|
}
|
|
}
|