title: integrate django password validators with django rest framework validate_password
body: <p>I'm trying to integrate <a href="https://docs.djangoproject.com/en/1.9/topics/auth/passwords/#integrating-validation" rel="noreferrer">django validators</a> 1.9 with django rest framework serializers. But the serialized 'user' (of django rest framework) is not compatible with the django validators.</p>
  
  <p>Here is the serializers.py</p>
  
  <pre><code>import django.contrib.auth.password_validation as validators
  from rest_framework import serializers
  
      class RegisterUserSerializer(serializers.ModelSerializer):
  
          password = serializers.CharField(style={'input_type': 'password'}, write_only=True)
  
          class Meta:
              model = User
              fields = ('id', 'username', 'email, 'password')
  
          def validate_password(self, data):
              validators.validate_password(password=data, user=User)
              return data
  
          def create(self, validated_data):
              user = User.objects.create_user(**validated_data)
              user.is_active = False
              user.save()
              return user
  </code></pre>
  
  <p>I managed to get MinimumLengthValidator and NumericPasswordValidator correct because both function validate don't use 'user' in validating. Source code is <a href="https://docs.djangoproject.com/en/1.9/_modules/django/contrib/auth/password_validation/#MinimumLengthValidator" rel="noreferrer">here</a></p>
  
  <p>Excerpt from django source code:</p>
  
  <pre><code>def validate(self, password, user=None):
          if password.isdigit():
              raise ValidationError(
                  _("This password is entirely numeric."),
                  code='password_entirely_numeric',
              )
  </code></pre>
  
  <p>For other validators like UserAttributeSimilarityValidator, the function uses another one argument 'user' in validating ('user' is django User model, if I'm not wrong)</p>
  
  <p>Excerpt from django source code:</p>
  
  <pre><code> def validate(self, password, user=None):
          if not user:
              return
  
          for attribute_name in self.user_attributes:
              value = getattr(user, attribute_name, None)
  </code></pre>
  
  <p><strong>How can I change serialized User into what django validators(UserAttributeSimilarityValidator) can see</strong></p>
  
  <p>Excerpt from django source code:</p>
  
  <pre><code>def validate(self, password, user=None):
          if not user:
              return
  
          for attribute_name in self.user_attributes:
              value = getattr(user, attribute_name, None)
              if not value or not isinstance(value, string_types):
                  continue
  </code></pre>
  
  <hr>
  
  <p><strong>Edit</strong></p>
  
  <p>Django Rest Framework can get all of Django's built-in password validation (but it's like a hack). Here's a problem:</p>
  
  <p>The validationError is like this</p>
  
  <blockquote>
    <p>[ValidationError(['This password is too short. It must contain at
    least 8 characters.']), ValidationError(['This password is entirely
    numeric.'])]</p>
  </blockquote>
  
  <p>The validation doesn't contain a field. Django rest framework see it as </p>
  
  <pre><code>{
      "non_field_errors": [
          "This password is too short. It must contain at least 8 characters.",
          "This password is entirely numeric."
      ]
  }
  </code></pre>
  
  <p>How can I inject a field at <code>raise ValidationError</code></p>