Reduce bcrypt iterations from 15 to 12 (common for 2025 processors)
This commit is contained in:
@@ -15,7 +15,7 @@ export const editUser = async (id: string, data: Prisma.UserUpdateInput) => {
|
|||||||
|
|
||||||
export const resetPassword = async (id: string) => {
|
export const resetPassword = async (id: string) => {
|
||||||
const password = Math.random().toString(36).slice(-8);
|
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({
|
const user = await prisma.user.update({
|
||||||
where: {
|
where: {
|
||||||
|
|||||||
@@ -1,56 +1,56 @@
|
|||||||
'use server';
|
"use server";
|
||||||
import { prisma, Prisma, PrismaClient } from '@repo/db';
|
import { prisma, Prisma, PrismaClient } from "@repo/db";
|
||||||
import { getServerSession } from '../../api/auth/[...nextauth]/auth';
|
import { getServerSession } from "../../api/auth/[...nextauth]/auth";
|
||||||
import bcrypt from 'bcryptjs';
|
import bcrypt from "bcryptjs";
|
||||||
|
|
||||||
export const unlinkDiscord = async (userId: string) => {
|
export const unlinkDiscord = async (userId: string) => {
|
||||||
const client = new PrismaClient();
|
const client = new PrismaClient();
|
||||||
await client.discordAccount.deleteMany({
|
await client.discordAccount.deleteMany({
|
||||||
where: {
|
where: {
|
||||||
userId,
|
userId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateUser = async (changes: Prisma.UserUpdateInput) => {
|
export const updateUser = async (changes: Prisma.UserUpdateInput) => {
|
||||||
const session = await getServerSession();
|
const session = await getServerSession();
|
||||||
if (!session) return null;
|
if (!session) return null;
|
||||||
|
|
||||||
const client = new PrismaClient();
|
const client = new PrismaClient();
|
||||||
|
|
||||||
await client.user.update({
|
await client.user.update({
|
||||||
where: {
|
where: {
|
||||||
id: session.user.id,
|
id: session.user.id,
|
||||||
},
|
},
|
||||||
data: changes,
|
data: changes,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const changePassword = async (
|
export const changePassword = async (
|
||||||
oldPassword: string,
|
oldPassword: string,
|
||||||
newPassword: string
|
newPassword: string,
|
||||||
) => {
|
) => {
|
||||||
const session = await getServerSession();
|
const session = await getServerSession();
|
||||||
if (!session)
|
if (!session)
|
||||||
return {
|
return {
|
||||||
error: 'User not found',
|
error: "User not found",
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!(await bcrypt.compare(oldPassword, session.user.password)))
|
if (!(await bcrypt.compare(oldPassword, session.user.password)))
|
||||||
return {
|
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({
|
await prisma.user.update({
|
||||||
data: {
|
data: {
|
||||||
password: hashedPassword,
|
password: hashedPassword,
|
||||||
},
|
},
|
||||||
where: {
|
where: {
|
||||||
id: session.user.id,
|
id: session.user.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export const resetPassword = async (email: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const password = Math.random().toString(36).slice(-8);
|
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({
|
await prisma.user.update({
|
||||||
where: {
|
where: {
|
||||||
email,
|
email,
|
||||||
|
|||||||
@@ -1,32 +1,32 @@
|
|||||||
'use server';
|
"use server";
|
||||||
import { prisma, Prisma } from '@repo/db';
|
import { prisma, Prisma } from "@repo/db";
|
||||||
import bcrypt from 'bcryptjs';
|
import bcrypt from "bcryptjs";
|
||||||
|
|
||||||
export const register = async ({
|
export const register = async ({
|
||||||
password,
|
password,
|
||||||
...user
|
...user
|
||||||
}: Omit<Prisma.UserCreateInput, 'publicId'>) => {
|
}: Omit<Prisma.UserCreateInput, "publicId">) => {
|
||||||
const hashedPassword = await bcrypt.hash(password, 15);
|
const hashedPassword = await bcrypt.hash(password, 12);
|
||||||
const lastUserPublicId = await prisma.user.findFirst({
|
const lastUserPublicId = await prisma.user.findFirst({
|
||||||
select: {
|
select: {
|
||||||
publicId: true,
|
publicId: true,
|
||||||
},
|
},
|
||||||
orderBy: {
|
orderBy: {
|
||||||
publicId: 'desc',
|
publicId: "desc",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
let varPublicId = 'VAR0000';
|
let varPublicId = "VAR0000";
|
||||||
if (lastUserPublicId) {
|
if (lastUserPublicId) {
|
||||||
const lastUserInt = parseInt(lastUserPublicId.publicId.replace('VAR', ''));
|
const lastUserInt = parseInt(lastUserPublicId.publicId.replace("VAR", ""));
|
||||||
varPublicId = `VAR${(lastUserInt + 1).toString().padStart(4, '0')}`;
|
varPublicId = `VAR${(lastUserInt + 1).toString().padStart(4, "0")}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const newUser = prisma.user.create({
|
const newUser = prisma.user.create({
|
||||||
data: {
|
data: {
|
||||||
...user,
|
...user,
|
||||||
publicId: varPublicId,
|
publicId: varPublicId,
|
||||||
password: hashedPassword,
|
password: hashedPassword,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
return newUser;
|
return newUser;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user