From 80a2c724d80ec12d76d3b9b11162e5d9ac9bf127 Mon Sep 17 00:00:00 2001 From: SauceyRed Date: Thu, 1 May 2025 22:29:53 +0200 Subject: [PATCH] feat: add hashing and validation utility functions --- utils/hashing.ts | 7 +++++++ utils/validation.ts | 3 +++ 2 files changed, 10 insertions(+) create mode 100644 utils/hashing.ts create mode 100644 utils/validation.ts diff --git a/utils/hashing.ts b/utils/hashing.ts new file mode 100644 index 0000000..847a9dc --- /dev/null +++ b/utils/hashing.ts @@ -0,0 +1,7 @@ +export async function hashPassword(password: string) { + const encodedPass = new TextEncoder().encode(password); + const hashBuffer = await crypto.subtle.digest("SHA-384", encodedPass); + const hashArray = Array.from(new Uint8Array(hashBuffer)); + const hashedPass = hashArray.map((b) => b.toString(16).padStart(2, "0")).join(""); + return hashedPass; +} \ No newline at end of file diff --git a/utils/validation.ts b/utils/validation.ts new file mode 100644 index 0000000..48e13ef --- /dev/null +++ b/utils/validation.ts @@ -0,0 +1,3 @@ +export function validateUsername(username: string) { + return /^[\w.-]+$/.test(username); +} \ No newline at end of file