From bb24ed53a4b4601c2cce9d0d5ecdc23e5db18f6d Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 29 Dec 2020 20:20:59 +0100 Subject: [PATCH] Switched to hased tokens based on uuid (to be canged) ref #56 --- src/models/actions/CreateStatsClient.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/models/actions/CreateStatsClient.ts b/src/models/actions/CreateStatsClient.ts index b46819d..c649426 100644 --- a/src/models/actions/CreateStatsClient.ts +++ b/src/models/actions/CreateStatsClient.ts @@ -1,6 +1,8 @@ +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'; + /** * This classed is used to create a new StatsClient entity from a json body (post request). */ @@ -22,11 +24,11 @@ export class CreateStatsClient { /** * Converts this to a StatsClient entity. */ - public toStatsClient(): StatsClient { + public async toStatsClient(): Promise { let newClient: StatsClient = new StatsClient(); newClient.description = this.description; - newClient.key = crypto.randomBytes(20).toString('hex'); + newClient.key = await argon2.hash(uuid.v4()); if (this.enabled === undefined || this.enabled === null) { newClient.enabled = true; } else { newClient.enabled = this.enabled }