fix: hash user passwords on update

This commit is contained in:
ponas committed 2026-11-03 03:52:41 +01:00
1 parent cd8de0847c
commit 83eb8f07f2
1 file changed
+6 -1
+6 -1
View File
@@ -37,7 +37,7 @@ class UserSerializer(serializers.ModelSerializer):
extra_kwargs = {'password': {'write_only': True}}
def _hash_password(self, raw_password):
return sha512_crypt.encrypt(raw_password)
return sha512_crypt.hash(raw_password)
def create(self, validated_data):
user = User(
@@ -47,3 +47,8 @@ class UserSerializer(serializers.ModelSerializer):
)
user.save()
return user
def update(self, instance, validated_data):
if 'password' in validated_data:
validated_data['password'] = self._hash_password(validated_data['password'])
return super().update(instance, validated_data)