Skip to content

The Open Source DocuSign Alternative.

Avoid user from setting the same old password

Ephraim Atta-Duncan2b9a2ff25062
diff --git a/apps/web/components/reset-password.tsx b/apps/web/components/reset-password.tsx
index f55a7628c..7cc38ce42 100644
--- a/apps/web/components/reset-password.tsx
+++ b/apps/web/components/reset-password.tsx
@@ -38,6 +38,24 @@ export default function ResetPassword(props: any) {
}
);
+ if (!response.ok) {
+ toast.dismiss();
+
+ if (response.status == 404) {
+ toast.error("Invalid Token");
+ }
+
+ if (response.status == 400) {
+ toast.error("New password must be different");
+ }
+
+ if (response.status == 500) {
+ toast.error("Something went wrong.");
+ }
+
+ return;
+ }
+
if (response.ok) {
setResetSuccessful(true);
setTimeout(() => {
diff --git a/apps/web/pages/api/auth/forgot-password.ts b/apps/web/pages/api/auth/forgot-password.ts
index 42d904fb7..7edab5aca 100644
--- a/apps/web/pages/api/auth/forgot-password.ts
+++ b/apps/web/pages/api/auth/forgot-password.ts
@@ -1,5 +1,5 @@
import { NextApiRequest, NextApiResponse } from "next";
-import { sendResetPassword, sendResetPasswordSuccessMail } from "@documenso/lib/mail";
+import { sendResetPassword } from "@documenso/lib/mail";
import { defaultHandler, defaultResponder } from "@documenso/lib/server";
import prisma from "@documenso/prisma";
import crypto from "crypto";
diff --git a/apps/web/pages/api/auth/reset-password.ts b/apps/web/pages/api/auth/reset-password.ts
index 4bf2e5306..c98de4809 100644
--- a/apps/web/pages/api/auth/reset-password.ts
+++ b/apps/web/pages/api/auth/reset-password.ts
@@ -1,5 +1,5 @@
import { NextApiRequest, NextApiResponse } from "next";
-import { hashPassword } from "@documenso/lib/auth";
+import { hashPassword, verifyPassword } from "@documenso/lib/auth";
import { sendResetPasswordSuccessMail } from "@documenso/lib/mail";
import { defaultHandler, defaultResponder } from "@documenso/lib/server";
import prisma from "@documenso/prisma";
@@ -22,7 +22,15 @@ async function postHandler(req: NextApiRequest, res: NextApiResponse) {
});
if (!foundToken) {
- return res.status(400).json({ message: "Invalid token." });
+ return res.status(404).json({ message: "Invalid token." });
+ }
+
+ const isSamePassword = await verifyPassword(password, foundToken.User.password!);
+
+ if (isSamePassword) {
+ return res
+ .status(400)
+ .json({ message: "New password must be different from the current password." });
}
const hashedPassword = await hashPassword(password);