feat: add hashing and validation utility functions
This commit is contained in:
parent
d401464353
commit
80a2c724d8
2 changed files with 10 additions and 0 deletions
7
utils/hashing.ts
Normal file
7
utils/hashing.ts
Normal 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
3
utils/validation.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
export function validateUsername(username: string) {
|
||||
return /^[\w.-]+$/.test(username);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue