Reduce bcrypt iterations from 15 to 12 (common for 2025 processors)

This commit is contained in:
Nicolas
2025-04-28 12:12:56 +02:00
parent c00b64d666
commit b5e96e02c3
4 changed files with 72 additions and 72 deletions

View File

@@ -15,7 +15,7 @@ export const editUser = async (id: string, data: Prisma.UserUpdateInput) => {
export const resetPassword = async (id: string) => {
const password = Math.random().toString(36).slice(-8);
const hashedPassword = await bcrypt.hash(password, 15);
const hashedPassword = await bcrypt.hash(password, 12);
const user = await prisma.user.update({
where: {

View File

@@ -1,7 +1,7 @@
'use server';
import { prisma, Prisma, PrismaClient } from '@repo/db';
import { getServerSession } from '../../api/auth/[...nextauth]/auth';
import bcrypt from 'bcryptjs';
"use server";
import { prisma, Prisma, PrismaClient } from "@repo/db";
import { getServerSession } from "../../api/auth/[...nextauth]/auth";
import bcrypt from "bcryptjs";
export const unlinkDiscord = async (userId: string) => {
const client = new PrismaClient();
@@ -28,20 +28,20 @@ export const updateUser = async (changes: Prisma.UserUpdateInput) => {
export const changePassword = async (
oldPassword: string,
newPassword: string
newPassword: string,
) => {
const session = await getServerSession();
if (!session)
return {
error: 'User not found',
error: "User not found",
};
if (!(await bcrypt.compare(oldPassword, session.user.password)))
return {
error: 'Old password is incorrect',
error: "Old password is incorrect",
};
const hashedPassword = await bcrypt.hash(newPassword, 15);
const hashedPassword = await bcrypt.hash(newPassword, 12);
await prisma.user.update({
data: {
password: hashedPassword,

View File

@@ -17,7 +17,7 @@ export const resetPassword = async (email: string) => {
}
const password = Math.random().toString(36).slice(-8);
const hashedPassword = await bcrypt.hash(password, 15);
const hashedPassword = await bcrypt.hash(password, 12);
await prisma.user.update({
where: {
email,

View File

@@ -1,24 +1,24 @@
'use server';
import { prisma, Prisma } from '@repo/db';
import bcrypt from 'bcryptjs';
"use server";
import { prisma, Prisma } from "@repo/db";
import bcrypt from "bcryptjs";
export const register = async ({
password,
...user
}: Omit<Prisma.UserCreateInput, 'publicId'>) => {
const hashedPassword = await bcrypt.hash(password, 15);
}: Omit<Prisma.UserCreateInput, "publicId">) => {
const hashedPassword = await bcrypt.hash(password, 12);
const lastUserPublicId = await prisma.user.findFirst({
select: {
publicId: true,
},
orderBy: {
publicId: 'desc',
publicId: "desc",
},
});
let varPublicId = 'VAR0000';
let varPublicId = "VAR0000";
if (lastUserPublicId) {
const lastUserInt = parseInt(lastUserPublicId.publicId.replace('VAR', ''));
varPublicId = `VAR${(lastUserInt + 1).toString().padStart(4, '0')}`;
const lastUserInt = parseInt(lastUserPublicId.publicId.replace("VAR", ""));
varPublicId = `VAR${(lastUserInt + 1).toString().padStart(4, "0")}`;
}
const newUser = prisma.user.create({