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