14 lines
498 B
TypeScript
14 lines
498 B
TypeScript
export const hashPassword = async (password: string): Promise<string> => {
|
|
const PASSWORD_SALT = Bun.env.PASSWORD_SALT!;
|
|
const saltedPassword = PASSWORD_SALT + password;
|
|
const encoder = new TextEncoder();
|
|
const data = encoder.encode(saltedPassword);
|
|
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
|
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
const hashHex = hashArray
|
|
.map((b) => b.toString(16).padStart(2, "0"))
|
|
.join("");
|
|
|
|
return hashHex;
|
|
};
|