diff --git a/apps/sim/app/api/chat/[identifier]/otp/route.ts b/apps/sim/app/api/chat/[identifier]/otp/route.ts index e518ceb28a5..f2130c622bf 100644 --- a/apps/sim/app/api/chat/[identifier]/otp/route.ts +++ b/apps/sim/app/api/chat/[identifier]/otp/route.ts @@ -1,4 +1,4 @@ -import { randomUUID } from 'crypto' +import { randomInt, randomUUID } from 'crypto' import { db } from '@sim/db' import { chat, verification } from '@sim/db/schema' import { createLogger } from '@sim/logger' @@ -17,7 +17,7 @@ import { createErrorResponse, createSuccessResponse } from '@/app/api/workflows/ const logger = createLogger('ChatOtpAPI') function generateOTP() { - return Math.floor(100000 + Math.random() * 900000).toString() + return randomInt(100000, 1000000).toString() } const OTP_EXPIRY = 15 * 60 // 15 minutes diff --git a/apps/sim/lib/core/security/encryption.ts b/apps/sim/lib/core/security/encryption.ts index 9f82f4c04da..ec2c19261db 100644 --- a/apps/sim/lib/core/security/encryption.ts +++ b/apps/sim/lib/core/security/encryption.ts @@ -76,8 +76,9 @@ export function generatePassword(length = 24): string { const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_-+=' let result = '' + const bytes = randomBytes(length) for (let i = 0; i < length; i++) { - result += chars.charAt(Math.floor(Math.random() * chars.length)) + result += chars.charAt(bytes[i] % chars.length) } return result