fix(task4): enforce unified password validation rule

This commit is contained in:
Atharv1705
2026-11-17 17:58:20 +05:30
parent c086833163
commit 5f649e3e4c
8 changed files with 264 additions and 29 deletions
@@ -43,8 +43,8 @@ export function ChangePasswordModal({ open, onClose }: ChangePasswordModalProps)
setErrorMsg("Please enter your current password.");
return;
}
if (!newPassword || newPassword.length < 6) {
setErrorMsg("New password must be at least 6 characters.");
if (!newPassword || newPassword.length < 8) {
setErrorMsg("New password must be at least 8 characters.");
return;
}
if (newPassword !== confirmPassword) {
@@ -73,7 +73,7 @@ export function ChangePasswordModal({ open, onClose }: ChangePasswordModalProps)
if (!next) handleClose();
}}
title="Change Password"
description="Update your account login password. Password must be at least 6 characters long."
description="Update your account login password."
className="max-w-md"
>
<form onSubmit={handleSubmit} className="space-y-4">
@@ -122,9 +122,9 @@ export function ChangePasswordModal({ open, onClose }: ChangePasswordModalProps)
value={newPassword}
onChange={(e) => setNewPassword(e.target.value)}
required
minLength={6}
minLength={8}
autoComplete="new-password"
placeholder="At least 6 characters"
placeholder="At least 8 characters"
className="w-full px-3 py-2 text-sm border border-gray-300 rounded-md pr-10 focus:outline-none focus:ring-2 focus:ring-blue-500"
/>
<button
@@ -136,6 +136,7 @@ export function ChangePasswordModal({ open, onClose }: ChangePasswordModalProps)
{showNew ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}
</button>
</div>
<p className="text-xs text-gray-500 mt-1">At least 8 characters, with a letter and a number.</p>
</div>
<div className="space-y-1">
+3 -2
View File
@@ -425,8 +425,8 @@ function buildUserSchema(isEdit: boolean) {
role: z.enum(["system_admin", "biomedical", "department_user", "management", "coordinator"]),
department_id: z.string().optional(),
password: isEdit
? z.string().refine((v) => v === "" || v.length >= 6, "Password must be at least 6 characters")
: z.string().min(6, "Password must be at least 6 characters"),
? z.string().refine((v) => v === "" || v.length >= 8, "Password must be at least 8 characters")
: z.string().min(8, "Password must be at least 8 characters"),
});
}
@@ -530,6 +530,7 @@ function UserModal({
{editing ? "New Password (leave blank to keep current)" : "Password *"}
</label>
<input {...register("password")} type="password" className={inputCls} />
<p className="text-xs text-gray-500 mt-1">At least 8 characters, with a letter and a number.</p>
{errors.password && <p className={errCls}>{errors.password.message}</p>}
</div>
<div className="flex justify-end gap-2 pt-2">