Updated the method of api key creation.

ref #56
This commit is contained in:
2020-12-29 20:49:45 +01:00
parent c4270b0839
commit 04813173e4
3 changed files with 35 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
import * as argon2 from "argon2";
import { IsBoolean, IsOptional, IsString } from 'class-validator';
import crypto from 'crypto';
import * as uuid from 'uuid';
import { StatsClient } from '../entities/StatsClient';
@@ -28,7 +29,12 @@ export class CreateStatsClient {
let newClient: StatsClient = new StatsClient();
newClient.description = this.description;
newClient.key = await argon2.hash(uuid.v4());
let newUUID = uuid.v4().toUpperCase();
newClient.prefix = crypto.createHash("sha3-512").update(newUUID).digest('hex').substring(0, 7).toUpperCase();
newClient.key = await argon2.hash(newClient.prefix + "." + newUUID);
newClient.cleartextkey = newClient.prefix + "." + newUUID;
if (this.enabled === undefined || this.enabled === null) { newClient.enabled = true; }
else { newClient.enabled = this.enabled }