title: Django rest framework password security for <script>
body: <p>I have implemented user registration in Django Rest Framework but I don't know how to check for sql injection and etc.<br>
  For example a password like this: "&lt; script>"</p>
  
  <pre><code>class UserRegisterSerializer(serializers.ModelSerializer):
  
  def validate(self, data):
      password = data['password']
      password2 = data['password2']
      data.pop('password2')
  
      if password != password2:
          raise serializers.ValidationError({"password": "Passwords must match."})
  
      errors = dict()
      try:
          # validate the password and catch the exception
          validators.validate_password(password)
  
      # the exception raised here is different than serializers.ValidationError
      except exceptions.ValidationError as e:
          errors['password'] = list(e.messages)
  
      if errors:
          raise serializers.ValidationError(errors)
  
      return data
  </code></pre>
  
  <p>This code is in my settings:</p>
  
  <pre><code>AUTH_PASSWORD_VALIDATORS = [
  {
      'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  },
  {
      'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', #=&gt; Default (8 characters)
      'OPTIONS': {
          'min_length': 4,
      }
  },
  {
      'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  },
  {
      'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  },
  </code></pre>