diff --git a/src/account/i18n/i18n.tsx b/src/account/i18n/i18n.tsx index 8601fa73..2183515e 100644 --- a/src/account/i18n/i18n.tsx +++ b/src/account/i18n/i18n.tsx @@ -211,7 +211,9 @@ const keycloakifyExtraMessages = { "shouldBeDifferent": "{0} should be different to {1}", "shouldMatchPattern": "Pattern should match: `/{0}/`", "mustBeAnInteger": "Must be an integer", - "notAValidOption": "Not a valid option" + "notAValidOption": "Not a valid option", + "newPasswordSameAsOld": "New password must be different from the old one", + "passwordConfirmNotMatch": "Password confirmation does not match" }, "fr": { /* spell-checker: disable */ @@ -223,7 +225,9 @@ const keycloakifyExtraMessages = { "logoutConfirmTitle": "Déconnexion", "logoutConfirmHeader": "Êtes-vous sûr(e) de vouloir vous déconnecter ?", - "doLogout": "Se déconnecter" + "doLogout": "Se déconnecter", + "newPasswordSameAsOld": "Le nouveau mot de passe doit être différent de l'ancien", + "passwordConfirmNotMatch": "La confirmation du mot de passe ne correspond pas" /* spell-checker: enable */ } }; diff --git a/src/account/pages/Password.tsx b/src/account/pages/Password.tsx index f8a14e47..9cd91df7 100644 --- a/src/account/pages/Password.tsx +++ b/src/account/pages/Password.tsx @@ -1,3 +1,4 @@ +import { useState } from "react"; import { clsx } from "keycloakify/tools/clsx"; import type { PageProps } from "keycloakify/account/pages/PageProps"; import { useGetClassName } from "keycloakify/account/lib/useGetClassName"; @@ -17,10 +18,69 @@ export default function Password(props: PageProps { + if (!password.passwordSet) { + return; + } + + if (newPassword === currentPassword) { + setNewPasswordError(msgStr("newPasswordSameAsOld")); + } else { + setNewPasswordError(""); + } + }; + + const checkNewPasswordConfirm = (newPasswordConfirm: string) => { + if (newPasswordConfirm === "") { + return; + } + + if (newPassword !== newPasswordConfirm) { + setNewPasswordConfirmError(msgStr("passwordConfirmNotMatch")); + } else { + setNewPasswordConfirmError(""); + } + }; return ( -