fix: hash user passwords on update
This commit is contained in:
1 file changed
+6
-1
@@ -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)
|
||||
Reference in new issue
Block a user