title: Validation inactive user Django
body: <p>I looking for a resolving of my issue.
  I have custom User model:</p>
  <pre><code>class User(AbstractUser):
      username = models.CharField(max_length=150, unique=True, blank=False, null=False)
      first_name = models.CharField(max_length=150, blank=True)
      last_name = models.CharField(max_length=150, blank=True)
      password = models.CharField(max_length=150, blank=False)
      email = models.EmailField(unique=True, blank=False)
      date_create = models.DateTimeField(auto_now_add=True)
      address = models.CharField(blank=True, max_length=128)
      phone = PhoneNumberField(unique=True)
      photo = models.ImageField(upload_to='images/', blank=True)
      is_active = models.BooleanField(default=True)
  </code></pre>
  <p>In my app I have e-mail-confirmation. When I create user I hit the &quot;is_active=False&quot;. When user activate account then flag &quot;is_active=True&quot;. Everything works good.
  But when INactive user tries to log in I wanna get message from Django in Login form.
  Django has it(source code):</p>
  <pre><code>def confirm_login_allowed(self, user):
          if not user.is_active:
              raise ValidationError(
                  self.error_messages['inactive'],
                  code='inactive',
              )
  </code></pre>
  <p>But doesn't work for me.
  Update: When inactive user tried to log in I get same message as user with incorrect username or password.
  I tried to override AuthenticationForm:</p>
  <pre><code>User = get_user_model()
  class CustomAuthenticationForm(AuthenticationForm):
      class Meta:                # tried with Meta and without
          model = User
      def confirm_login_allowed(self, user):
          if not user.is_active:
              raise forms.ValidationError('There was a problem with your login.')
  </code></pre>
  <p>View:</p>
  <pre><code>class CustomLoginView(SuccessMessageMixin, LoginView):
      form_class = CustomAuthenticationForm
      success_url = reverse_lazy('home')
      success_message = &quot;You was logged in successfully&quot;
  </code></pre>
  <p>url:</p>
  <pre><code>path('login/', CustomLoginView.as_view(), name='login'),
  </code></pre>
  <p>Update, templates base and login:</p>
  <pre><code>&lt;!doctype html&gt;
  {% load static %}
  &lt;html lang=&quot;en&quot;&gt;
  &lt;head&gt;
      &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css&quot;
            integrity=&quot;sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2&quot; crossorigin=&quot;anonymous&quot;&gt;
      &lt;script src=&quot;https://code.jquery.com/jquery-3.5.1.slim.min.js&quot;
              integrity=&quot;sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj&quot;
              crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js&quot;
              integrity=&quot;sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx&quot;
              crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;
  
      {% block mystyle %}
      {% endblock %}
  &lt;/head&gt;
  &lt;body&gt;
  &lt;nav class=&quot;navbar navbar-expand-lg navbar-dark bg-dark justify-content-center&quot;&gt;
      &lt;a class=&quot;navbar-brand&quot; href=&quot;#&quot;&gt;Site&lt;/a&gt;
      &lt;button class=&quot;navbar-toggler&quot; type=&quot;button&quot; data-toggle=&quot;collapse&quot; data-target=&quot;#navbarNavAltMarkup&quot;
              aria-controls=&quot;navbarNavAltMarkup&quot; aria-expanded=&quot;false&quot; aria-label=&quot;Toggle navigation&quot;&gt;
          &lt;span class=&quot;navbar-toggler-icon&quot;&gt;&lt;/span&gt;
      &lt;/button&gt;
      &lt;div class=&quot;collapse navbar-collapse&quot; id=&quot;navbarNavAltMarkup&quot;&gt;
          &lt;div class=&quot;navbar-nav&quot;&gt;
              &lt;a class=&quot;nav-link&quot; href=&quot;{% url 'home' %}&quot;&gt;Home&lt;/a&gt;
              {% if user.is_authenticated %}
              &lt;a class=&quot;nav-link&quot; href=&quot;{% url 'cabinet' %}&quot;&gt;Cabinet&lt;/a&gt;
              &lt;a class=&quot;nav-link&quot; href=&quot;{% url 'logout' %}&quot;&gt;LogOut&lt;/a&gt;
              {% else%}
              &lt;a class=&quot;nav-link&quot; href=&quot;{% url 'signup' %}&quot;&gt;SignUp&lt;/a&gt;
              &lt;a class=&quot;nav-link text-right&quot; href=&quot;{% url 'login' %}&quot;&gt;LogIn&lt;/a&gt;
              {% endif %}
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/nav&gt;
  {% if messages %}
  {% for message in messages %}
  &lt;div class=&quot;alert alert-success&quot;&gt;{{ message }}&lt;/div&gt;
  {% endfor %}
  {% endif %}
  {% block content %}
  {% endblock %}
  &lt;/body&gt;
  &lt;/html&gt;
  
  {% extends &quot;base.html&quot; %}
  {% load crispy_forms_tags %}
  &lt;!DOCTYPE html&gt;
  {% block title %}Log In{% endblock %}
  {% block content %}
  &lt;h1 class=&quot;row justify-content-center p-4&quot;&gt;Log In&lt;/h1&gt;
  &lt;div class=&quot;row justify-content-center&quot;&gt;
      &lt;div class=&quot;col-4&quot;&gt;
          &lt;form autocomplete=&quot;off&quot; method=&quot;post&quot;&gt;
              {% csrf_token %}
              {{ form|crispy }}
              &lt;div class=&quot;container p-2&quot;&gt;
                  &lt;a href=&quot;{% url 'password_reset' %}&quot;&gt;Forgot your password?&lt;/a&gt;
              &lt;/div&gt;
              &lt;div class=&quot;container p-2&quot;&gt;
                  &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot;&gt;Submit&lt;/button&gt;
              &lt;/div&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  {% endblock %}
  </code></pre>
  <p>Could someone help me? Thanks.</p>