feat: add hashing and validation utility functions

This commit is contained in:
SauceyRed 2025-05-01 22:29:53 +02:00
parent d401464353
commit 80a2c724d8
Signed by: sauceyred
GPG key ID: 270B096EF6E9A462
2 changed files with 10 additions and 0 deletions

7
utils/hashing.ts Normal file
View file

@ -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;
}

3
utils/validation.ts Normal file
View file

@ -0,0 +1,3 @@
export function validateUsername(username: string) {
return /^[\w.-]+$/.test(username);
}