Wouldn't it be possible to implement case-insensitive usernames without loosing backwards compatibility, by checking the username iexact and only if there are multiple possibilities fall back to the old case-sensitive variant?
So something like this: diff --git a/django/contrib/auth/base_user.py b/django/contrib/auth/base_user.py index 34dd6ac2f2..748db8bf89 100644 --- a/django/contrib/auth/base_user.py +++ b/django/contrib/auth/base_user.py @@ -4,6 +4,7 @@ not in INSTALLED_APPS. """ import unicodedata +from django.core.exceptions import MultipleObjectsReturned from django.contrib.auth import password_validation from django.contrib.auth.hashers import ( check_password, is_password_usable, make_password, @@ -41,7 +42,14 @@ class BaseUserManager(models.Manager): return get_random_string(length, allowed_chars) def get_by_natural_key(self, username): - return self.get(**{self.model.USERNAME_FIELD: username}) + username_field = self.model.USERNAME_FIELD + + # Try case-insensitive match of username. + # If there are multiple possiblities fallback to case-sensitive lookup + try: + return self.get(**{username_field + '__iexac': username}) + except MultipleObjectsReturned: + return self.get(**{username_field: username}) class AbstractBaseUser(models.Model): -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To post to this group, send email to django-developers@googlegroups.com. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/cc07fa69-06b3-4d24-aa2c-e5201ebe936a%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.