Skip to content

Commit

Permalink
Password must change when changing password
Browse files Browse the repository at this point in the history
  • Loading branch information
meshy committed Aug 10, 2015
1 parent 3cc8c95 commit 3c391a9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v12.0.1 (Upcoming)

* Ensure new and old passwords differ when changing password.

## v12.0.0

* Update factories to use `class Meta:` syntax instead of `FACTORY_FOR`.
Expand Down
3 changes: 3 additions & 0 deletions user_management/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ def validate(self, attrs):
if attrs.get('new_password') != attrs['new_password2']:
msg = _('Your new passwords do not match.')
raise serializers.ValidationError({'new_password2': msg})
if attrs.get('old_password') == attrs.get('new_password'):
msg = _('Your password has not changed.')
raise serializers.ValidationError({'new_password': msg})
return attrs


Expand Down
15 changes: 15 additions & 0 deletions user_management/api/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,21 @@ def test_deserialize_mismatched_passwords(self):
})
self.assertFalse(serializer.is_valid())

def test_no_change_password(self):
"""A password cannot be changed if it doesn't change!"""
password = 'Same_passw0rd'

user = UserFactory.create(password=password)

serializer = serializers.PasswordChangeSerializer(user, data={
'old_password': password,
'new_password': password,
'new_password2': password,
}
)
self.assertFalse(serializer.is_valid())
self.assertIn('new_password', serializer.errors)


class PasswordResetSerializerTest(TestCase):
def test_deserialize_passwords(self):
Expand Down

0 comments on commit 3c391a9

Please sign in to comment.