title: Custom user no password in db
body: <p>When I try logging in with my custom user model I have been getting 'Please enter a correct email and password. Note that both fields may be case-sensitive.'. When I check the database I see the superuser has a password but my test user does not.</p>
  <p>Things I've tried:</p>
  <ul>
  <li>Checking database for users (They're present but no password)</li>
  <li>Dropping database and running makemigrations</li>
  <li>Superuser can login on both admin and regular login form just fine</li>
  </ul>
  <p><strong>accounts/models.py</strong></p>
  <pre><code>from django.db import models
  from django.contrib.auth.models import (
      AbstractBaseUser, 
      BaseUserManager,
      PermissionsMixin,
  )
  
  # Create your models here.
  
  
  class UserManager(BaseUserManager):
      def create_user(self, email, first_name, last_name, company, phone, is_active=True, is_admin=False, is_staff=False, is_dealer=False, password=None):
          if not email:
              raise ValueError(&quot;Users must have an email address&quot;)
          if not password:
              raise ValueError(&quot;Users must have a password&quot;)
          if not first_name:
              raise ValueError(&quot;Users must have a first name&quot;)
          if not last_name:
              raise ValueError(&quot;Users must have a last name&quot;)
          if not company:
              raise ValueError(&quot;Users must have a company&quot;)
          if not phone:
              raise ValueError(&quot;Users must have a phone number&quot;)
          user_obj = self.model(
              email = self.normalize_email(email)
          )
          user_obj.set_password(password)
          user_obj.first_name = first_name
          user_obj.last_name = last_name
          user_obj.company = company
          user_obj.phone = phone
          user_obj.admin = is_admin
          user_obj.staff = is_staff
          user_obj.dealer = is_dealer
          user_obj.active = is_active
          user_obj.save(using=self._db)
          return user_obj
  
      def create_superuser(self, email, first_name, last_name, company, phone, password=None):
          user = self.create_user(
              email,
              first_name,
              last_name,
              company,
              phone,
              password=password,
              is_admin=True,
              is_staff=True
          )
          return user
  
      def create_company_staff_user(self, email, first_name, last_name, company, phone, password=None):
          user = self.create_user(
              email,
              first_name,
              last_name,
              company,
              phone,
              password=password,
              is_staff=True
          )
          return user
      
      def create_dealer_user(self, email, first_name, last_name, company, phone, password=None):
          user = self.create_user(
              email,
              first_name,
              last_name,
              company,
              phone,
              password=password,
              is_dealer=True
          )
          return user
  
  
  class User(AbstractBaseUser, PermissionsMixin):
      email = models.EmailField(max_length=255, unique=True)
      first_name = models.CharField(max_length=255, blank=True, null=True)
      last_name = models.CharField(max_length=255, blank=True, null=True)
      company = models.CharField(max_length=255, blank=True, null=True)
      phone = models.CharField(max_length=255, blank=True, null=True)
      active = models.BooleanField(default=True) # can login
      online = models.BooleanField(default=False)
      admin = models.BooleanField(default=False)
      staff = models.BooleanField(default=False)
      dealer = models.BooleanField(default=False)
      timestamp = models.DateTimeField(auto_now_add=True)
      
      USERNAME_FIELD = 'email'
      # USERNAME_FIELD and password are required by default
      REQUIRED_FIELDS = ['first_name', 'last_name', 'company', 'phone']
  
      objects = UserManager()
  
      def __str__(self):
          return f&quot;{self.first_name} {self.last_name}&quot;
  
      def get_full_name(self):
          return f&quot;{self.first_name} {self.last_name}&quot;
  
      def has_perm(self, perm, obj=None):
          &quot;Does the user have a specific permission?&quot;
          # Simplest possible answer: Yes, always
          return True
  
      def has_module_perms(self, app_label):
          &quot;Does the user have permissions to view the app `app_label`?&quot;
          # Simplest possible answer: Yes, always
          return True
  
      @property
      def is_admin(self):
          return self.admin
  
      @property
      def is_staff(self):
          return self.staff
  
      @property
      def is_dealer(self):
          return self.dealer  
  
      @property
      def is_active(self):
          return self.active
  
      @property
      def is_online(self):
          return self.online  
  </code></pre>
  <p><strong>accounts/admin.py</strong></p>
  <pre><code>from django.contrib import admin
  from django.contrib.auth import get_user_model
  
  # Register your models here.
  
  User = get_user_model()
  
  admin.site.register(User)
  </code></pre>
  <p><strong>settings.py</strong></p>
  <pre><code>AUTH_USER_MODEL = 'accounts.User'
  </code></pre>
  <p><strong>main/templates/registration/login.html</strong></p>
  <pre><code>&lt;div class=&quot;container&quot;&gt;
    &lt;div class=&quot;card my-4&quot;&gt;
      {% load static %}
      &lt;img class=&quot;img-fluid pb-4&quot; src=&quot;{% static 'img/logos/logo-black.png' %}&quot;&gt;
  
      {% if form.errors %}
      &lt;p&gt;Your username and password didn't match. Please try again.&lt;/p&gt;
      {% endif %}
  
      {% if next %}
      {% if user.is_authenticated %}
      &lt;p&gt;Your account doesn't have access to this page. To proceed,
        please login with an account that has access.&lt;/p&gt;
      {% else %}
      &lt;p&gt;Please login to see this page.&lt;/p&gt;
      {% endif %}
      {% endif %}
  
      &lt;form method=&quot;post&quot; action=&quot;{% url 'login' %}&quot;&gt;
        {% csrf_token %}
        {{ form|crispy }}
        &lt;button type=&quot;submit&quot; class=&quot;btn btn-success&quot;&gt;&lt;i class=&quot;fas fa-sign-in-alt&quot;&gt;&lt;/i&gt; Login&lt;/button&gt;
        &lt;input type=&quot;hidden&quot; name=&quot;next&quot; value=&quot;{{ next }}&quot; /&gt;
      &lt;/form&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  <p><strong>myproject/urls.py</strong></p>
  <pre><code>urlpatterns = [
      path(&quot;&quot;, include('main.urls')),
      path('accounts/', include('django.contrib.auth.urls')), 
      path('admin/', admin.site.urls),
  ]  + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
  </code></pre>
  <p>I don't know what else to try. All I need is to be able to sign in with email rather than a username and have two types of users. (staff and dealer)</p>
  <p>EDIT: I just checked my database and it appears there is not a password for my test user.</p>