админка
This commit is contained in:
@@ -3,28 +3,25 @@
|
||||
namespace App\Services;
|
||||
|
||||
use App\Exceptions\DuplicateGameAccountException;
|
||||
use Brick\Math\BigInteger;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class AzerothCoreAccountRegistrar
|
||||
{
|
||||
private const string MODULUS_HEX = '894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB3C82872A3E9BB7';
|
||||
|
||||
private const int GENERATOR = 7;
|
||||
|
||||
private const int BYTE_LENGTH = 32;
|
||||
public function __construct(private readonly AzerothCoreSrpService $srp)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{id: int, username: string}
|
||||
*/
|
||||
public function register(string $username, string $email, string $password): array
|
||||
{
|
||||
$normalizedUsername = $this->normalizeUpperOnlyLatin(trim($username));
|
||||
$normalizedPassword = $this->normalizeUpperOnlyLatin($password);
|
||||
$normalizedEmail = $this->normalizeUpperOnlyLatin(trim($email));
|
||||
[$saltHex, $verifierHex] = $this->makeRegistrationData($normalizedUsername, $normalizedPassword);
|
||||
$normalizedUsername = $this->srp->normalizeUsername($username);
|
||||
$normalizedPassword = $this->srp->normalizePassword($password);
|
||||
$normalizedEmail = $this->srp->normalizeEmail($email);
|
||||
[$saltHex, $verifierHex] = $this->srp->makeRegistrationData($normalizedUsername, $normalizedPassword);
|
||||
|
||||
$connection = DB::connection(config('moonwell.auth_connection'));
|
||||
|
||||
@@ -97,30 +94,6 @@ class AzerothCoreAccountRegistrar
|
||||
return $connection->table('account')->where($column, $value)->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{0: string, 1: string}
|
||||
*/
|
||||
private function makeRegistrationData(string $username, string $password): array
|
||||
{
|
||||
$salt = random_bytes(self::BYTE_LENGTH);
|
||||
$innerDigest = hash('sha1', sprintf('%s:%s', $username, $password), true);
|
||||
$xDigest = hash('sha1', $salt.$innerDigest, true);
|
||||
$modulus = BigInteger::fromBase(self::MODULUS_HEX, 16);
|
||||
$exponent = BigInteger::fromBytes(strrev($xDigest), false);
|
||||
$verifier = BigInteger::of(self::GENERATOR)->modPow($exponent, $modulus);
|
||||
$verifierBytes = strrev(str_pad($verifier->toBytes(false), self::BYTE_LENGTH, "\0", STR_PAD_LEFT));
|
||||
|
||||
return [
|
||||
strtoupper(bin2hex($salt)),
|
||||
strtoupper(bin2hex($verifierBytes)),
|
||||
];
|
||||
}
|
||||
|
||||
private function normalizeUpperOnlyLatin(string $value): string
|
||||
{
|
||||
return strtoupper($value);
|
||||
}
|
||||
|
||||
private function isDuplicateKeyException(QueryException $exception): bool
|
||||
{
|
||||
return (string) $exception->getCode() === '23000';
|
||||
|
||||
Reference in New Issue
Block a user