From cac2d81b5cf9452c798f14b66fe5415a88c4e8a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20Paul=20Ton=C4=8Dik?= Date: Fri, 3 Jul 2026 13:14:05 +0200 Subject: [PATCH] fix(auth): prevention for same old and new password --- service/src/main/inse/auth/service.py | 10 ++++++++++ .../src/app/modules/account/account.component.ts | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/service/src/main/inse/auth/service.py b/service/src/main/inse/auth/service.py index d822d92c..0af15a4b 100644 --- a/service/src/main/inse/auth/service.py +++ b/service/src/main/inse/auth/service.py @@ -1080,6 +1080,16 @@ def change_password( detail="Current password is incorrect.", ) + if current_password == new_password: + logger.warning( + "Password change failed: new password is the same as the current password for account %s", + account.id, + ) + raise HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, + detail="New password cannot be the same as the current password.", + ) + account.password_hash = _hash_password(new_password) account.epoch += 1 diff --git a/webapp/src/app/modules/account/account.component.ts b/webapp/src/app/modules/account/account.component.ts index d4a9b5aa..8b3eec70 100644 --- a/webapp/src/app/modules/account/account.component.ts +++ b/webapp/src/app/modules/account/account.component.ts @@ -120,6 +120,21 @@ export class AccountComponent { return null; }); + + validate(schemaPath.newPassword, ({ value }) => { + const oldPassword = this.changePasswordModel().oldPassword.trim(); + const newPassword = value().trim(); + + if (oldPassword && newPassword && oldPassword === newPassword) { + return { + kind: 'passwordSameAsOld', + message: + 'Neues Passwort darf nicht dasselbe wie das alte Passwort sein.', + }; + } + + return null; + }); }, { submission: {