Skip to content

Commit

Permalink
fix: handle properly invalid fields in ForcePasswordChangeForm
Browse files Browse the repository at this point in the history
  • Loading branch information
damien.rabois committed Feb 1, 2024
1 parent 0960b69 commit 21646ab
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file.

## [0.0.6] - 2024-02-01

### Bug Fixes

- Handle properly invalid fields in `ForcePasswordChangeForm`

## [0.0.5] - 2024-01-31

### Features
Expand Down
17 changes: 9 additions & 8 deletions password_rotate/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ class ForcePasswordChangeForm(PasswordChangeForm):
def clean(self):
cleaned_data = super().clean()

ratio = fuzz.ratio(
self.cleaned_data["old_password"],
cleaned_data["new_password1"]
)
if ratio >= settings.PASSWORD_ROTATE_MAX_SIMILARITY_RATIO:
raise ValidationError(
{"new_password1": _("The new password is too similar to the old one.")},
code="password_similar"
if cleaned_data.get("old_password") and cleaned_data.get("new_password1"):
ratio = fuzz.ratio(
cleaned_data["old_password"],
cleaned_data["new_password1"]
)
if ratio >= settings.PASSWORD_ROTATE_MAX_SIMILARITY_RATIO:
raise ValidationError(
{"new_password1": _("The new password is too similar to the old one.")},
code="password_similar"
)
return cleaned_data

0 comments on commit 21646ab

Please sign in to comment.