title: check_password() from a user again
body: <p>I have the following form. How can I check the password from the user again, before the user can change his email address finally? Even if the user is logged in, I just want to be sure that it is really the user. Just a security thing.</p>
  <p>How do I do it with <code>.check_password()</code>?</p>
  <pre><code>'EmailChangeForm' object has no attribute 'user'
  
  /home/craphunter/workspace/project/trunk/project/auth/user/email_change/forms.py in clean_password, line 43
  </code></pre>
  <pre class="lang-py prettyprint-override"><code>from django import forms
  from django.db.models.loading import cache
  from django.utils.translation import ugettext_lazy as _
  from django.contrib.auth.models import User
  
  
  class EmailChangeForm(forms.Form):
      
      email = forms.EmailField(label='New E-mail', max_length=75)
      password = forms.CharField(widget=forms.PasswordInput)
  
      def __init__(self, user, *args, **kwargs):
          super(EmailChangeForm, self).__init__(*args, **kwargs)
          self.user = user
  
      def clean_password(self):
          valid = self.user.check_password(self.cleaned_data['password'])
          if not valid:
              raise forms.ValidationError(&quot;Password Incorrect&quot;)
          return valid
      
      def __init__(self, username=None, *args, **kwargs):
          &quot;&quot;&quot;Constructor.
          
          **Mandatory arguments**
          
          ``username``
              The username of the user that requested the email change.
          
          &quot;&quot;&quot;
          self.username = username
          super(EmailChangeForm, self).__init__(*args, **kwargs)
      
      def clean_email(self):
          &quot;&quot;&quot;Checks whether the new email address differs from the user's current
          email address.
          
          &quot;&quot;&quot;
          email = self.cleaned_data.get('email')
          
          User = cache.get_model('auth', 'User')
          user = User.objects.get(username__exact=self.username)
          
          # Check if the new email address differs from the current email address.
          if user.email == email:
              raise forms.ValidationError('New email address cannot be the same \
                  as your current email address')
          
          return email
  </code></pre>