# Authentication Form Customize, Doubles Field.

**URL:** <https://forum.djangoproject.com/t/authentication-form-customize-doubles-field/14245>\
**Category:** Forms & APIs\
**Created:** [June 12, 2022, 6:52pm UTC](https://forum.djangoproject.com/t/authentication-form-customize-doubles-field/14245 "2022-06-12T18:52:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AhmdMWddh](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ahmdmwddh/32/21707_2.png) [@AhmdMWddh](https://forum.djangoproject.com/u/AhmdMWddh)\
**Post date:** [June 12, 2022, 6:52pm UTC](https://forum.djangoproject.com/t/authentication-form-customize-doubles-field/14245/1 "2022-06-12T18:52:37Z")

</div>

The Goal is To Customize Form, Then Pass it to LoginView.

I am using AuthenticationForm after Customizing it, but i see it repeats extra one input,  
I guess it is for username, i need only two inputs, E-Mail and Password.  
any advice.  
Forms:

```auto
class AccountSignInForm(AuthenticationForm):
    email = forms.EmailField(widget=forms.EmailInput(attrs={'placeholder': 'E-Mail..'}), label='E-Mail')
    password = forms.CharField(widget=forms.PasswordInput(attrs={'placeholder': 'Password..'}), label='Password')

    class Meta:
        model = Account
        fields = ['email', 'password']

```

Urls:

```auto
app_name = 'accounts'

urlpatterns = [
    path('sign-in', views.AccountLoginView.as_view(), name='login'),
]

```

Views:

```auto
class AccountLoginView(LoginView):
    template_name = 'accounts/login.html'
    form_class = AccountSignInForm
    success_url = 'HomePageView'

```

HTML:

```auto
<h1>Login Form</h1>
<form method="POST">
	{% csrf_token %}
    {% for field in form %}
        <div>{{ field.label }}</div>
        <div>{{ field }}</div>
    {% endfor %}
    <input type="submit" value="Login" />
</form>

```

![LoginForm](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/6/6fffa91a2f4a308c318531f3933679e6b0a24398.png)

---

<div class="post-metadata">

**Author:** ![urimeba](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/urimeba/32/8348_2.png) [@urimeba](https://forum.djangoproject.com/u/urimeba)\
**Post date:** [June 13, 2022, 8:44am UTC](https://forum.djangoproject.com/t/authentication-form-customize-doubles-field/14245/2 "2022-06-13T08:44:37Z")

</div>

Hello @AhmdMWddh  
As you say, the extra field is for the username field.  
You can see it here: [django/forms.py at main · django/django · GitHub](https://github.com/django/django/blob/main/django/contrib/auth/forms.py)  
What you could do if you don’t want the “username” field being showed inside the form is to override it to a hidden input.  
Just remember that this won’t work if you didn’t customize also your authentication module. What I mean is that Django, by default, uses the username and password fields to login. The email field is there only for information purposes.  
If you want to use the email field as “username” field, at least for authentication, you need to create a model inheriting from “AbstractUser” and set the USERNAME\_FIELD property to email. You could also write your own authentication module, but option needs more work involved.  
You can see more information about the first option here: [Add custom field to Django Admin authentication form - Stack Overflow](https://stackoverflow.com/questions/63685570/add-custom-field-to-django-admin-authentication-form)  
Greetings

---

<div class="post-metadata">

**Author:** ![AhmdMWddh](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ahmdmwddh/32/21707_2.png) [@AhmdMWddh](https://forum.djangoproject.com/u/AhmdMWddh)\
**Post date:** [June 14, 2022, 12:16pm UTC](https://forum.djangoproject.com/t/authentication-form-customize-doubles-field/14245/3 "2022-06-14T12:16:42Z")

</div>

Great Thanks Urimeba,  
Yes, I have this Custom User with `USERNAME_FIELD = email` thanks for information pal.

```auto

class UserManager(BaseUserManager):
    def create_user(self, email, first_name, last_name, password=None):
        if not email:
            raise ValueError('E-Mail is Required, Please Provide Your E-Mail.')
        if not first_name:
            raise ValueError('E-Mail is Required, Please Provide Your First Name.')
        if not last_name:
            raise ValueError('E-Mail is Required, Please Provide Your Last Name.')
        user = self.model(
            email=self.normalize_email(email),
            first_name=first_name,
            last_name=last_name
        )
        user.is_staff = True
        user.set_password(password)
        user.save(using=self._db)
        return user

    def create_superuser(self, email, first_name, last_name, password=None):
        user = self.create_user(
            email=self.normalize_email(email),
            first_name=first_name,
            last_name=last_name,
            password=password
        )
        user.is_superuser = True
        user.save(using=self._db)
        return user

class User(AbstractBaseUser):
    email = models.EmailField(verbose_name='email', max_length=255, unique=True)
    first_name = models.CharField(verbose_name='First Name', max_length=255)
    last_name = models.CharField(verbose_name='Last Name', max_length=255)
    date_joined = models.DateTimeField(verbose_name='date joined', auto_now_add=True)
    last_login = models.DateTimeField(verbose_name='last login', auto_now=True)
    is_active = models.BooleanField(default=True)
    is_staff = models.BooleanField(default=False)
    is_superuser = models.BooleanField(default=False)

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['first_name', 'last_name']

    objects = UserManager()

    @property
    def full_name(self):
        return f'{self.first_name} {self.last_name}'

    def __str__ (self):
        return f'{self.email} - {self.full_name}'

    def has_perm(self, perm, obj=None):
        return self.is_staff

    def has_module_perms(self, app_label):
        return True

```
