diff --git a/djoser/conf.py b/djoser/conf.py index dc85a039..a3fcae6e 100644 --- a/djoser/conf.py +++ b/djoser/conf.py @@ -34,6 +34,7 @@ def __getattribute__(self, item): "SEND_CONFIRMATION_EMAIL": False, "USER_CREATE_PASSWORD_RETYPE": False, "SET_PASSWORD_RETYPE": False, + "DUPLICATION_PASSWORD_CHECK": False, "PASSWORD_RESET_CONFIRM_RETYPE": False, "SET_USERNAME_RETYPE": False, "USERNAME_RESET_CONFIRM_RETYPE": False, diff --git a/djoser/serializers.py b/djoser/serializers.py index 805bf01c..63504194 100644 --- a/djoser/serializers.py +++ b/djoser/serializers.py @@ -178,6 +178,11 @@ def validate(self, attrs): try: uid = utils.decode_uid(self.initial_data.get("uid", "")) self.user = User.objects.get(pk=uid) + # check's the new given password to be not same as current password in DB + if settings.DUPLICATION_PASSWORD_CHECK: + new_password = self.initial_data.get("new_password" , None) + if new_password and self.user.check_password(new_password): + raise ValidationError({"password": "New password cannot be the same as current password"}) except (User.DoesNotExist, ValueError, TypeError, OverflowError): key_error = "invalid_uid" raise ValidationError(