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: {