title: Password Reset activation Link
body: <p>I have 2 views .
  1) For user Registration .
  2) For Password Reset.
  Activation Link for both task is generated and send to mail.
  My activation link for first time registration is working fine .
  When I create my activation Link for password Reset , It is not get expired after use.</p>
  
  <pre><code>@csrf_protect
  def changing_password_confirmation(request, uidb64, token):
      try:
          uid = force_bytes(urlsafe_base64_decode(uidb64))
          user = User.objects.get(pk=uid)
      except(TypeError, ValueError, OverflowError, User.DoesNotExist):
          user = None
      if user is not None and passord_reset_token.check_token(user, token):
          print('user is not None and passord_reset_token.check_token(user, token)')
          if request.method == 'POST':
              password1 = request.POST.get('password1')
              password2 = request.POST.get('password2')
              if password1 == password2:
                  user.set_password(password1)
                  user.save()
                  return render(request=request, template_name='website/password_reset_complete.html')
              else:
                  return HttpResponse('&lt;h1&gt;Password doesnt match&lt;/h1&gt;')
          return render(request=request, template_name='website/password_reset_confirm.html')
      else:
          print('User', user)
          result = 'Activation link is invalid!'
          return render(request=request, template_name='website/password_reset_confirm.html', context={'result': result})
  </code></pre>
  
  <pre><code>from django.contrib.auth.tokens import PasswordResetTokenGenerator
  from django.utils import six
  
  
  class TokenGenerator(PasswordResetTokenGenerator):
      def _make_hash_value(self, user, timestamp):
          return (
                  six.text_type(user.pk) + six.text_type(timestamp) +
                  six.text_type(user.is_active)
          )
  
  
  class PasswordTokenGenerator(PasswordResetTokenGenerator):
      def _make_hash_value(self, user, timestamp):
          return (
                  six.text_type(user.pk) + six.text_type(timestamp) +
                  six.text_type(user.is_active)
          )
  account_activation_token = TokenGenerator()
  passord_reset_token = PasswordTokenGenerator()
  
  </code></pre>
  
  <p>Reset Password Template</p>
  
  <pre><code>{% extends "website/header.html" %}
  
  {% block title %}Enter new password{% endblock %}
  
  {% block content %}
  
  {% if validlink %}
  &lt;h1&gt;Set a new password!&lt;/h1&gt;
  &lt;form method="POST"&gt;
      {% csrf_token %}
      &lt;div class="form-group"&gt;
          Password: &lt;input type="text" class="form-control" name='password1' placeholder="password" value=""/&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          Repeat Password: &lt;input type="text" class="form-control" name='password2' placeholder="confirm" value=""/&gt;
      &lt;/div&gt;
      &lt;input type="submit" value="Change my password"&gt;
  &lt;/form&gt;
  
  {% else %}
  {{ result }}
  {% endif %}
  
  {% endblock %}```
  </code></pre>