We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Username case sensitivity
Usernames are case sensitive. The importer makes all usernames lowercase, but automatically created accounts when logging in with Kerberos authentification can have uppercase letters.
This can lead to two users having the same username and then the system crashed on login.

Automatically created accounts should also get lowercase usernames, even if the user enters the name differently.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `evap/evaluation/forms.py`
Content:
```
1 from django import forms
2 from django.contrib.auth import authenticate
3 from django.utils.translation import ugettext_lazy as _
4 from django.views.decorators.debug import sensitive_variables
5 
6 from evap.evaluation.models import UserProfile
7 
8 
9 class LoginUsernameForm(forms.Form):
10     """Form encapsulating the login with username and password, for example from an Active Directory.
11     """
12 
13     username = forms.CharField(label=_("Username"), max_length=254)
14     password = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
15 
16     def __init__(self, request=None, *args, **kwargs):
17         """
18         If request is passed in, the form will validate that cookies are
19         enabled. Note that the request (a HttpRequest object) must have set a
20         cookie with the key TEST_COOKIE_NAME and value TEST_COOKIE_VALUE before
21         running this validation.
22         """
23         self.request = request
24         self.user_cache = None
25         super().__init__(*args, **kwargs)
26 
27     @sensitive_variables('password')
28     def clean_password(self):
29         username = self.cleaned_data.get('username')
30         password = self.cleaned_data.get('password')
31 
32         if username and password:
33             self.user_cache = authenticate(username=username, password=password)
34             if self.user_cache is None:
35                 raise forms.ValidationError(_("Please enter a correct username and password."))
36         self.check_for_test_cookie()
37         return password
38 
39     def check_for_test_cookie(self):
40         if self.request and not self.request.session.test_cookie_worked():
41             raise forms.ValidationError(_("Your Web browser doesn't appear to have cookies enabled. Cookies are required for logging in."))
42 
43     def get_user_id(self):
44         if self.user_cache:
45             return self.user_cache.id
46         return None
47 
48     def get_user(self):
49         return self.user_cache
50 
51 
52 class NewKeyForm(forms.Form):
53     email = forms.EmailField(label=_("Email address"))
54 
55     def __init__(self, *args, **kwargs):
56         self.user_cache = None
57 
58         super().__init__(*args, **kwargs)
59 
60     def clean_email(self):
61         email = self.cleaned_data.get('email')
62 
63         if not UserProfile.email_needs_login_key(email):
64             raise forms.ValidationError(_("HPI users cannot request login keys. Please login using your domain credentials."))
65 
66         try:
67             user = UserProfile.objects.get(email__iexact=email)
68             self.user_cache = user
69         except UserProfile.DoesNotExist:
70             raise forms.ValidationError(_("No user with this email address was found. Please make sure to enter the email address already known to the university office."))
71 
72         return email
73 
74     def get_user(self):
75         return self.user_cache
76
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/evap/evaluation/forms.py b/evap/evaluation/forms.py
--- a/evap/evaluation/forms.py
+++ b/evap/evaluation/forms.py
@@ -29,6 +29,9 @@
         username = self.cleaned_data.get('username')
         password = self.cleaned_data.get('password')
 
+        # django-auth-kerberos might create a new userprofile. make sure it gets a lowercase username.
+        username = username.lower()
+
         if username and password:
             self.user_cache = authenticate(username=username, password=password)
             if self.user_cache is None:

{"golden_diff": "diff --git a/evap/evaluation/forms.py b/evap/evaluation/forms.py\n--- a/evap/evaluation/forms.py\n+++ b/evap/evaluation/forms.py\n@@ -29,6 +29,9 @@\n         username = self.cleaned_data.get('username')\n         password = self.cleaned_data.get('password')\n \n+        # django-auth-kerberos might create a new userprofile. make sure it gets a lowercase username.\n+        username = username.lower()\n+\n         if username and password:\n             self.user_cache = authenticate(username=username, password=password)\n             if self.user_cache is None:\n", "issue": "Username case sensitivity\nUsernames are case sensitive. The importer makes all usernames lowercase, but automatically created accounts when logging in with Kerberos authentification can have uppercase letters.\nThis can lead to two users having the same username and then the system crashed on login.\n\nAutomatically created accounts should also get lowercase usernames, even if the user enters the name differently.\n\n", "before_files": [{"content": "from django import forms\nfrom django.contrib.auth import authenticate\nfrom django.utils.translation import ugettext_lazy as _\nfrom django.views.decorators.debug import sensitive_variables\n\nfrom evap.evaluation.models import UserProfile\n\n\nclass LoginUsernameForm(forms.Form):\n    \"\"\"Form encapsulating the login with username and password, for example from an Active Directory.\n    \"\"\"\n\n    username = forms.CharField(label=_(\"Username\"), max_length=254)\n    password = forms.CharField(label=_(\"Password\"), widget=forms.PasswordInput)\n\n    def __init__(self, request=None, *args, **kwargs):\n        \"\"\"\n        If request is passed in, the form will validate that cookies are\n        enabled. Note that the request (a HttpRequest object) must have set a\n        cookie with the key TEST_COOKIE_NAME and value TEST_COOKIE_VALUE before\n        running this validation.\n        \"\"\"\n        self.request = request\n        self.user_cache = None\n        super().__init__(*args, **kwargs)\n\n    @sensitive_variables('password')\n    def clean_password(self):\n        username = self.cleaned_data.get('username')\n        password = self.cleaned_data.get('password')\n\n        if username and password:\n            self.user_cache = authenticate(username=username, password=password)\n            if self.user_cache is None:\n                raise forms.ValidationError(_(\"Please enter a correct username and password.\"))\n        self.check_for_test_cookie()\n        return password\n\n    def check_for_test_cookie(self):\n        if self.request and not self.request.session.test_cookie_worked():\n            raise forms.ValidationError(_(\"Your Web browser doesn't appear to have cookies enabled. Cookies are required for logging in.\"))\n\n    def get_user_id(self):\n        if self.user_cache:\n            return self.user_cache.id\n        return None\n\n    def get_user(self):\n        return self.user_cache\n\n\nclass NewKeyForm(forms.Form):\n    email = forms.EmailField(label=_(\"Email address\"))\n\n    def __init__(self, *args, **kwargs):\n        self.user_cache = None\n\n        super().__init__(*args, **kwargs)\n\n    def clean_email(self):\n        email = self.cleaned_data.get('email')\n\n        if not UserProfile.email_needs_login_key(email):\n            raise forms.ValidationError(_(\"HPI users cannot request login keys. Please login using your domain credentials.\"))\n\n        try:\n            user = UserProfile.objects.get(email__iexact=email)\n            self.user_cache = user\n        except UserProfile.DoesNotExist:\n            raise forms.ValidationError(_(\"No user with this email address was found. Please make sure to enter the email address already known to the university office.\"))\n\n        return email\n\n    def get_user(self):\n        return self.user_cache\n", "path": "evap/evaluation/forms.py"}], "after_files": [{"content": "from django import forms\nfrom django.contrib.auth import authenticate\nfrom django.utils.translation import ugettext_lazy as _\nfrom django.views.decorators.debug import sensitive_variables\n\nfrom evap.evaluation.models import UserProfile\n\n\nclass LoginUsernameForm(forms.Form):\n    \"\"\"Form encapsulating the login with username and password, for example from an Active Directory.\n    \"\"\"\n\n    username = forms.CharField(label=_(\"Username\"), max_length=254)\n    password = forms.CharField(label=_(\"Password\"), widget=forms.PasswordInput)\n\n    def __init__(self, request=None, *args, **kwargs):\n        \"\"\"\n        If request is passed in, the form will validate that cookies are\n        enabled. Note that the request (a HttpRequest object) must have set a\n        cookie with the key TEST_COOKIE_NAME and value TEST_COOKIE_VALUE before\n        running this validation.\n        \"\"\"\n        self.request = request\n        self.user_cache = None\n        super().__init__(*args, **kwargs)\n\n    @sensitive_variables('password')\n    def clean_password(self):\n        username = self.cleaned_data.get('username')\n        password = self.cleaned_data.get('password')\n\n        # django-auth-kerberos might create a new userprofile. make sure it gets a lowercase username.\n        username = username.lower()\n\n        if username and password:\n            self.user_cache = authenticate(username=username, password=password)\n            if self.user_cache is None:\n                raise forms.ValidationError(_(\"Please enter a correct username and password.\"))\n        self.check_for_test_cookie()\n        return password\n\n    def check_for_test_cookie(self):\n        if self.request and not self.request.session.test_cookie_worked():\n            raise forms.ValidationError(_(\"Your Web browser doesn't appear to have cookies enabled. Cookies are required for logging in.\"))\n\n    def get_user_id(self):\n        if self.user_cache:\n            return self.user_cache.id\n        return None\n\n    def get_user(self):\n        return self.user_cache\n\n\nclass NewKeyForm(forms.Form):\n    email = forms.EmailField(label=_(\"Email address\"))\n\n    def __init__(self, *args, **kwargs):\n        self.user_cache = None\n\n        super().__init__(*args, **kwargs)\n\n    def clean_email(self):\n        email = self.cleaned_data.get('email')\n\n        if not UserProfile.email_needs_login_key(email):\n            raise forms.ValidationError(_(\"HPI users cannot request login keys. Please login using your domain credentials.\"))\n\n        try:\n            user = UserProfile.objects.get(email__iexact=email)\n            self.user_cache = user\n        except UserProfile.DoesNotExist:\n            raise forms.ValidationError(_(\"No user with this email address was found. Please make sure to enter the email address already known to the university office.\"))\n\n        return email\n\n    def get_user(self):\n        return self.user_cache\n", "path": "evap/evaluation/forms.py"}]}