Repository: rotki/rotki

Issue:
Inability to login if username contains a '.' after 1.31.0
## Problem Definition

If the user has a username that contains a '.' then in the autocomplete prompt at login the name appears only up to the `.`.

## Logs

There is a username with a '.' in the directory
![2023-11-25_18-32](https://github.com/rotki/rotki/assets/1658405/ff589757-faa4-4b4e-86f0-6eb8925d9409)

The autocomplete does not show it. Only shows content before the dot.
![2023-11-25_18-32_1](https://github.com/rotki/rotki/assets/1658405/efb0d694-b844-41cf-bf54-e2563ed68b68)

Even if the user hand-types the rest the frontend ignores it and takes the name only up to the '.'


https://github.com/rotki/rotki/assets/1658405/a26447f5-86e6-40ca-ac84-35ef8f259fe6


### System Description

Operating system: ALL
Rotki version: 1.31.0

## Task

- Find out why and fix it
- Make sure that all valid username characters work fine

## Solution for users until this is fixed

You can just go to the rotki data directory of your OS: https://rotki.readthedocs.io/en/latest/usage_guide.html#rotki-data-directory
Find the username with the '.' and edit it to not have it. Then restart rotki and username should be detected fine.


Discussion:

Resolving patch:
diff --git a/rotkehlchen/data_handler.py b/rotkehlchen/data_handler.py
--- a/rotkehlchen/data_handler.py
+++ b/rotkehlchen/data_handler.py
@@ -172,7 +172,7 @@ def get_users(self) -> dict[str, str]:
         for x in self.data_directory.iterdir():
             try:
                 if x.is_dir() and (x / 'rotkehlchen.db').exists():
-                    users[x.stem] = 'loggedin' if x.stem == self.username else 'loggedout'
+                    users[x.name] = 'loggedin' if x.name == self.username else 'loggedout'
             except PermissionError:
                 # ignore directories that can't be accessed
                 continue


Test patch:
diff --git a/rotkehlchen/tests/api/test_users.py b/rotkehlchen/tests/api/test_users.py
--- a/rotkehlchen/tests/api/test_users.py
+++ b/rotkehlchen/tests/api/test_users.py
@@ -94,31 +94,41 @@ def test_user_creation(rotkehlchen_api_server, data_dir):
     """Test that PUT at user endpoint can create a new user"""
     # Create a user without any premium credentials
     async_query = random.choice([False, True])
-    username = 'hania'
-    data = {'name': username, 'password': '1234', 'async_query': async_query}
+    usernames = ('hania', 'john.doe')
     rotki = rotkehlchen_api_server.rest_api.rotkehlchen
 
-    with ExitStack() as stack:
-        patch_no_op_unlock(rotki, stack)
-        response = requests.put(api_url_for(rotkehlchen_api_server, 'usersresource'), json=data)
+    for idx, username in enumerate(usernames):
+        data = {'name': username, 'password': '1234', 'async_query': async_query}
+        with ExitStack() as stack:
+            patch_no_op_unlock(rotki, stack)
+            response = requests.put(api_url_for(rotkehlchen_api_server, 'usersresource'), json=data)  # noqa: E501
 
-        if async_query is True:
-            task_id = assert_ok_async_response(response)
-            outcome = wait_for_async_task(rotkehlchen_api_server, task_id)
-            result = outcome['result']
-        else:
-            result = assert_proper_response_with_result(response)
+            if async_query is True:
+                task_id = assert_ok_async_response(response)
+                outcome = wait_for_async_task(rotkehlchen_api_server, task_id)
+                result = outcome['result']
+            else:
+                result = assert_proper_response_with_result(response)
 
-    check_proper_unlock_result(result, {'submit_usage_analytics': True})
+        check_proper_unlock_result(result, {'submit_usage_analytics': True})
 
-    # Query users and make sure the new user is logged in
-    response = requests.get(api_url_for(rotkehlchen_api_server, 'usersresource'))
-    result = assert_proper_response_with_result(response)
-    assert result[username] == 'loggedin'
-    assert len(result) == 1
+        # Query users and make sure the new user is logged in
+        response = requests.get(api_url_for(rotkehlchen_api_server, 'usersresource'))
+        result = assert_proper_response_with_result(response)
+        assert result[username] == 'loggedin'
+        assert len(result) == idx + 1
 
-    # Check that the directory was created
-    assert Path(data_dir / username / 'rotkehlchen.db').exists()
+        # Check that the directory was created
+        assert Path(data_dir / username / 'rotkehlchen.db').exists()
+
+        # Logout
+        data = {'action': 'logout'}
+        response = requests.patch(
+            api_url_for(rotkehlchen_api_server, 'usersbynameresource', name=username),
+            json=data,
+        )
+        assert_simple_ok_response(response)
+        assert rotki.user_is_logged_in is False
 
 
 @pytest.mark.parametrize('start_with_logged_in_user', [False])