﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
26951	AuthenticationForm bug when USERNAME_FIELD is an IntegerField	Gavin Wahl	Olexander Yermakov	"In my custom user model, my USERNAME field is an IntegerField (the users log in with their account number). I also subclass AuthenticationForm to make the username a forms.IntegerField.

`django.contrib.auth.forms.AuthenticationForm.clean` attempts to check if the username field was filled out by using the truthiness of the submitted value:

{{{#!python
    def clean(self):
        username = self.cleaned_data.get('username')
        password = self.cleaned_data.get('password')

        if username and password:
            self.user_cache = authenticate(username=username,
                                           password=password)
}}}

So, if someone attempts to log in with a username of `0`, authentication is never even attempted (but the form passes validation!), and the login view fails when triying to call auth.login.

The code should explicitly check for None as a sentinel value (`if username is not None and password is not None:`, rather than the truthiness of the submitted value."	Bug	closed	contrib.auth	1.9	Normal	fixed			Accepted	1	0	0	0	1	0
