Implement safe crypto
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
"use server";
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
import { prisma, Prisma } from "@repo/db";
|
||||
import bcrypt from "bcryptjs";
|
||||
import { sendMailByTemplate } from "../../../../helper/mail";
|
||||
@@ -14,7 +13,11 @@ export const editUser = async (id: string, data: Prisma.UserUpdateInput) => {
|
||||
};
|
||||
|
||||
export const resetPassword = async (id: string) => {
|
||||
const password = Math.random().toString(36).slice(-8);
|
||||
const array = new Uint8Array(8);
|
||||
crypto.getRandomValues(array);
|
||||
const password = Array.from(array, (byte) =>
|
||||
("0" + (byte % 36).toString(36)).slice(-1),
|
||||
).join("");
|
||||
const hashedPassword = await bcrypt.hash(password, 12);
|
||||
|
||||
const user = await prisma.user.update({
|
||||
|
||||
Reference in New Issue
Block a user