title: Why is checking if two passwords match in Django so complicated?
body: <p>Am I doing something wrong, or is this <em>seriously</em> what the developers expect me to write every time I want to check if two fields are the same?</p>
  
  <pre><code>def clean(self):
      data = self.cleaned_data
      if "password1" in data and "password2" in data:
          if data["password1"] != data["password2"]:
              self._errors["password2"] = self.error_class(['Passwords do not match.'])
              del data['password2']    
      return data
  </code></pre>
  
  <p>And why do I have to validate that the username is unique?</p>
  
  <pre><code>def clean_username(self):
      data = self.cleaned_data['username']
      if User.objects.filter(username=data).exists():
          raise ValidationError('Username already taken.')
      return data
  </code></pre>
  
  <p>It's a <code>ModelForm</code>. It should already know there's a unique constraint?</p>