We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
refining the default password scheme
In https://github.com/Mailu/Mailu/pull/647 the default scheme was switched to BCRYPT. The argumentation was:

> bcrypt is fast¹ and secure[...]

While it's actually secure, bcypt is not fast. It is _designed_ to be slow - to consume a very high amount of CPU resources to make brute-force attacs expensive.

Unfortunately, such a password scheme is not a good choice for a stateless system where many auth checks are done in a very short time. The current bcrypt strength of 12 consumes ~0.7s of CPU time for each authentication.

This might work for low-volume sites but can easily max out multiple cpus if there's some user traffic.

We should default to something alternative like PBKDF2 that ensures fast response times for auth requests.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `core/admin/mailu/configuration.py`
Content:
```
1 import os
2 
3 from socrate import system
4 
5 DEFAULT_CONFIG = {
6     # Specific to the admin UI
7     'DOCKER_SOCKET': 'unix:///var/run/docker.sock',
8     'BABEL_DEFAULT_LOCALE': 'en',
9     'BABEL_DEFAULT_TIMEZONE': 'UTC',
10     'BOOTSTRAP_SERVE_LOCAL': True,
11     'RATELIMIT_STORAGE_URL': '',
12     'QUOTA_STORAGE_URL': '',
13     'DEBUG': False,
14     'DOMAIN_REGISTRATION': False,
15     'TEMPLATES_AUTO_RELOAD': True,
16     # Database settings
17     'DB_FLAVOR': None,
18     'DB_USER': 'mailu',
19     'DB_PW': None,
20     'DB_HOST': 'database',
21     'DB_NAME': 'mailu',
22     'SQLITE_DATABASE_FILE':'data/main.db',
23     'SQLALCHEMY_DATABASE_URI': 'sqlite:////data/main.db',
24     'SQLALCHEMY_TRACK_MODIFICATIONS': False,
25     # Statistics management
26     'INSTANCE_ID_PATH': '/data/instance',
27     'STATS_ENDPOINT': '0.{}.stats.mailu.io',
28     # Common configuration variables
29     'SECRET_KEY': 'changeMe',
30     'DOMAIN': 'mailu.io',
31     'HOSTNAMES': 'mail.mailu.io,alternative.mailu.io,yetanother.mailu.io',
32     'POSTMASTER': 'postmaster',
33     'TLS_FLAVOR': 'cert',
34     'AUTH_RATELIMIT': '10/minute;1000/hour',
35     'DISABLE_STATISTICS': False,
36     # Mail settings
37     'DMARC_RUA': None,
38     'DMARC_RUF': None,
39     'WELCOME': False,
40     'WELCOME_SUBJECT': 'Dummy welcome topic',
41     'WELCOME_BODY': 'Dummy welcome body',
42     'DKIM_SELECTOR': 'dkim',
43     'DKIM_PATH': '/dkim/{domain}.{selector}.key',
44     'DEFAULT_QUOTA': 1000000000,
45     # Web settings
46     'SITENAME': 'Mailu',
47     'WEBSITE': 'https://mailu.io',
48     'WEB_ADMIN': '/admin',
49     'WEB_WEBMAIL': '/webmail',
50     'WEBMAIL': 'none',
51     'RECAPTCHA_PUBLIC_KEY': '',
52     'RECAPTCHA_PRIVATE_KEY': '',
53     # Advanced settings
54     'PASSWORD_SCHEME': 'BLF-CRYPT',
55     'LOG_LEVEL': 'WARNING',
56     # Host settings
57     'HOST_IMAP': 'imap',
58     'HOST_LMTP': 'imap:2525',
59     'HOST_POP3': 'imap',
60     'HOST_SMTP': 'smtp',
61     'HOST_AUTHSMTP': 'smtp',
62     'HOST_ADMIN': 'admin',
63     'ANTISPAM': 'none',
64     'HOST_ANTISPAM': 'antispam:11334',
65     'WEBMAIL': 'none',
66     'HOST_WEBMAIL': 'webmail',
67     'HOST_WEBDAV': 'webdav:5232',
68     'HOST_REDIS': 'redis',
69     'HOST_FRONT': 'front',
70     'SUBNET': '192.168.203.0/24',
71     'POD_ADDRESS_RANGE': None
72 }
73 
74 class ConfigManager(dict):
75     """ Naive configuration manager that uses environment only
76     """
77 
78     DB_TEMPLATES = {
79         'sqlite': 'sqlite:////{SQLITE_DATABASE_FILE}',
80         'postgresql': 'postgresql://{DB_USER}:{DB_PW}@{DB_HOST}/{DB_NAME}',
81         'mysql': 'mysql://{DB_USER}:{DB_PW}@{DB_HOST}/{DB_NAME}'
82     }
83 
84     def __init__(self):
85         self.config = dict()
86 
87     def get_host_address(self, name):
88         # if MYSERVICE_ADDRESS is defined, use this
89         if '{}_ADDRESS'.format(name) in os.environ:
90             return os.environ.get('{}_ADDRESS'.format(name))
91         # otherwise use the host name and resolve it
92         return system.resolve_address(self.config['HOST_{}'.format(name)])
93 
94     def resolve_hosts(self):
95         self.config["IMAP_ADDRESS"] = self.get_host_address("IMAP")
96         self.config["POP3_ADDRESS"] = self.get_host_address("POP3")
97         self.config["AUTHSMTP_ADDRESS"] = self.get_host_address("AUTHSMTP")
98         self.config["SMTP_ADDRESS"] = self.get_host_address("SMTP")
99         self.config["REDIS_ADDRESS"] = self.get_host_address("REDIS")
100         if self.config["WEBMAIL"] != "none":
101             self.config["WEBMAIL_ADDRESS"] = self.get_host_address("WEBMAIL")
102         if self.config["ANTISPAM"] != "none":
103             self.config["ANTISPAM_ADDRESS"] = self.get_host_address("ANTISPAM")
104 
105     def __coerce_value(self, value):
106         if isinstance(value, str) and value.lower() in ('true','yes'):
107             return True
108         elif isinstance(value, str) and value.lower() in ('false', 'no'):
109             return False
110         return value
111 
112     def init_app(self, app):
113         self.config.update(app.config)
114         # get environment variables
115         self.config.update({
116             key: self.__coerce_value(os.environ.get(key, value))
117             for key, value in DEFAULT_CONFIG.items()
118         })
119         self.resolve_hosts()
120 
121         # automatically set the sqlalchemy string
122         if self.config['DB_FLAVOR']:
123             template = self.DB_TEMPLATES[self.config['DB_FLAVOR']]
124             self.config['SQLALCHEMY_DATABASE_URI'] = template.format(**self.config)
125 
126         self.config['RATELIMIT_STORAGE_URL'] = 'redis://{0}/2'.format(self.config['REDIS_ADDRESS'])
127         self.config['QUOTA_STORAGE_URL'] = 'redis://{0}/1'.format(self.config['REDIS_ADDRESS'])
128         # update the app config itself
129         app.config = self
130 
131     def setdefault(self, key, value):
132         if key not in self.config:
133             self.config[key] = value
134         return self.config[key]
135 
136     def get(self, *args):
137         return self.config.get(*args)
138 
139     def keys(self):
140         return self.config.keys()
141 
142     def __getitem__(self, key):
143         return self.config.get(key)
144 
145     def __setitem__(self, key, value):
146         self.config[key] = value
147 
148     def __contains__(self, key):
149         return key in self.config
150
```
--- 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/core/admin/mailu/configuration.py b/core/admin/mailu/configuration.py
--- a/core/admin/mailu/configuration.py
+++ b/core/admin/mailu/configuration.py
@@ -51,7 +51,7 @@
     'RECAPTCHA_PUBLIC_KEY': '',
     'RECAPTCHA_PRIVATE_KEY': '',
     # Advanced settings
-    'PASSWORD_SCHEME': 'BLF-CRYPT',
+    'PASSWORD_SCHEME': 'PBKDF2',
     'LOG_LEVEL': 'WARNING',
     # Host settings
     'HOST_IMAP': 'imap',

{"golden_diff": "diff --git a/core/admin/mailu/configuration.py b/core/admin/mailu/configuration.py\n--- a/core/admin/mailu/configuration.py\n+++ b/core/admin/mailu/configuration.py\n@@ -51,7 +51,7 @@\n     'RECAPTCHA_PUBLIC_KEY': '',\n     'RECAPTCHA_PRIVATE_KEY': '',\n     # Advanced settings\n-    'PASSWORD_SCHEME': 'BLF-CRYPT',\n+    'PASSWORD_SCHEME': 'PBKDF2',\n     'LOG_LEVEL': 'WARNING',\n     # Host settings\n     'HOST_IMAP': 'imap',\n", "issue": "refining the default password scheme\nIn https://github.com/Mailu/Mailu/pull/647 the default scheme was switched to BCRYPT. The argumentation was:\r\n\r\n> bcrypt is fast\u00b9 and secure[...]\r\n\r\nWhile it's actually secure, bcypt is not fast. It is _designed_ to be slow - to consume a very high amount of CPU resources to make brute-force attacs expensive.\r\n\r\nUnfortunately, such a password scheme is not a good choice for a stateless system where many auth checks are done in a very short time. The current bcrypt strength of 12 consumes ~0.7s of CPU time for each authentication.\r\n\r\nThis might work for low-volume sites but can easily max out multiple cpus if there's some user traffic.\r\n\r\nWe should default to something alternative like PBKDF2 that ensures fast response times for auth requests.\n", "before_files": [{"content": "import os\n\nfrom socrate import system\n\nDEFAULT_CONFIG = {\n    # Specific to the admin UI\n    'DOCKER_SOCKET': 'unix:///var/run/docker.sock',\n    'BABEL_DEFAULT_LOCALE': 'en',\n    'BABEL_DEFAULT_TIMEZONE': 'UTC',\n    'BOOTSTRAP_SERVE_LOCAL': True,\n    'RATELIMIT_STORAGE_URL': '',\n    'QUOTA_STORAGE_URL': '',\n    'DEBUG': False,\n    'DOMAIN_REGISTRATION': False,\n    'TEMPLATES_AUTO_RELOAD': True,\n    # Database settings\n    'DB_FLAVOR': None,\n    'DB_USER': 'mailu',\n    'DB_PW': None,\n    'DB_HOST': 'database',\n    'DB_NAME': 'mailu',\n    'SQLITE_DATABASE_FILE':'data/main.db',\n    'SQLALCHEMY_DATABASE_URI': 'sqlite:////data/main.db',\n    'SQLALCHEMY_TRACK_MODIFICATIONS': False,\n    # Statistics management\n    'INSTANCE_ID_PATH': '/data/instance',\n    'STATS_ENDPOINT': '0.{}.stats.mailu.io',\n    # Common configuration variables\n    'SECRET_KEY': 'changeMe',\n    'DOMAIN': 'mailu.io',\n    'HOSTNAMES': 'mail.mailu.io,alternative.mailu.io,yetanother.mailu.io',\n    'POSTMASTER': 'postmaster',\n    'TLS_FLAVOR': 'cert',\n    'AUTH_RATELIMIT': '10/minute;1000/hour',\n    'DISABLE_STATISTICS': False,\n    # Mail settings\n    'DMARC_RUA': None,\n    'DMARC_RUF': None,\n    'WELCOME': False,\n    'WELCOME_SUBJECT': 'Dummy welcome topic',\n    'WELCOME_BODY': 'Dummy welcome body',\n    'DKIM_SELECTOR': 'dkim',\n    'DKIM_PATH': '/dkim/{domain}.{selector}.key',\n    'DEFAULT_QUOTA': 1000000000,\n    # Web settings\n    'SITENAME': 'Mailu',\n    'WEBSITE': 'https://mailu.io',\n    'WEB_ADMIN': '/admin',\n    'WEB_WEBMAIL': '/webmail',\n    'WEBMAIL': 'none',\n    'RECAPTCHA_PUBLIC_KEY': '',\n    'RECAPTCHA_PRIVATE_KEY': '',\n    # Advanced settings\n    'PASSWORD_SCHEME': 'BLF-CRYPT',\n    'LOG_LEVEL': 'WARNING',\n    # Host settings\n    'HOST_IMAP': 'imap',\n    'HOST_LMTP': 'imap:2525',\n    'HOST_POP3': 'imap',\n    'HOST_SMTP': 'smtp',\n    'HOST_AUTHSMTP': 'smtp',\n    'HOST_ADMIN': 'admin',\n    'ANTISPAM': 'none',\n    'HOST_ANTISPAM': 'antispam:11334',\n    'WEBMAIL': 'none',\n    'HOST_WEBMAIL': 'webmail',\n    'HOST_WEBDAV': 'webdav:5232',\n    'HOST_REDIS': 'redis',\n    'HOST_FRONT': 'front',\n    'SUBNET': '192.168.203.0/24',\n    'POD_ADDRESS_RANGE': None\n}\n\nclass ConfigManager(dict):\n    \"\"\" Naive configuration manager that uses environment only\n    \"\"\"\n\n    DB_TEMPLATES = {\n        'sqlite': 'sqlite:////{SQLITE_DATABASE_FILE}',\n        'postgresql': 'postgresql://{DB_USER}:{DB_PW}@{DB_HOST}/{DB_NAME}',\n        'mysql': 'mysql://{DB_USER}:{DB_PW}@{DB_HOST}/{DB_NAME}'\n    }\n\n    def __init__(self):\n        self.config = dict()\n\n    def get_host_address(self, name):\n        # if MYSERVICE_ADDRESS is defined, use this\n        if '{}_ADDRESS'.format(name) in os.environ:\n            return os.environ.get('{}_ADDRESS'.format(name))\n        # otherwise use the host name and resolve it\n        return system.resolve_address(self.config['HOST_{}'.format(name)])\n\n    def resolve_hosts(self):\n        self.config[\"IMAP_ADDRESS\"] = self.get_host_address(\"IMAP\")\n        self.config[\"POP3_ADDRESS\"] = self.get_host_address(\"POP3\")\n        self.config[\"AUTHSMTP_ADDRESS\"] = self.get_host_address(\"AUTHSMTP\")\n        self.config[\"SMTP_ADDRESS\"] = self.get_host_address(\"SMTP\")\n        self.config[\"REDIS_ADDRESS\"] = self.get_host_address(\"REDIS\")\n        if self.config[\"WEBMAIL\"] != \"none\":\n            self.config[\"WEBMAIL_ADDRESS\"] = self.get_host_address(\"WEBMAIL\")\n        if self.config[\"ANTISPAM\"] != \"none\":\n            self.config[\"ANTISPAM_ADDRESS\"] = self.get_host_address(\"ANTISPAM\")\n\n    def __coerce_value(self, value):\n        if isinstance(value, str) and value.lower() in ('true','yes'):\n            return True\n        elif isinstance(value, str) and value.lower() in ('false', 'no'):\n            return False\n        return value\n\n    def init_app(self, app):\n        self.config.update(app.config)\n        # get environment variables\n        self.config.update({\n            key: self.__coerce_value(os.environ.get(key, value))\n            for key, value in DEFAULT_CONFIG.items()\n        })\n        self.resolve_hosts()\n\n        # automatically set the sqlalchemy string\n        if self.config['DB_FLAVOR']:\n            template = self.DB_TEMPLATES[self.config['DB_FLAVOR']]\n            self.config['SQLALCHEMY_DATABASE_URI'] = template.format(**self.config)\n\n        self.config['RATELIMIT_STORAGE_URL'] = 'redis://{0}/2'.format(self.config['REDIS_ADDRESS'])\n        self.config['QUOTA_STORAGE_URL'] = 'redis://{0}/1'.format(self.config['REDIS_ADDRESS'])\n        # update the app config itself\n        app.config = self\n\n    def setdefault(self, key, value):\n        if key not in self.config:\n            self.config[key] = value\n        return self.config[key]\n\n    def get(self, *args):\n        return self.config.get(*args)\n\n    def keys(self):\n        return self.config.keys()\n\n    def __getitem__(self, key):\n        return self.config.get(key)\n\n    def __setitem__(self, key, value):\n        self.config[key] = value\n\n    def __contains__(self, key):\n        return key in self.config\n", "path": "core/admin/mailu/configuration.py"}], "after_files": [{"content": "import os\n\nfrom socrate import system\n\nDEFAULT_CONFIG = {\n    # Specific to the admin UI\n    'DOCKER_SOCKET': 'unix:///var/run/docker.sock',\n    'BABEL_DEFAULT_LOCALE': 'en',\n    'BABEL_DEFAULT_TIMEZONE': 'UTC',\n    'BOOTSTRAP_SERVE_LOCAL': True,\n    'RATELIMIT_STORAGE_URL': '',\n    'QUOTA_STORAGE_URL': '',\n    'DEBUG': False,\n    'DOMAIN_REGISTRATION': False,\n    'TEMPLATES_AUTO_RELOAD': True,\n    # Database settings\n    'DB_FLAVOR': None,\n    'DB_USER': 'mailu',\n    'DB_PW': None,\n    'DB_HOST': 'database',\n    'DB_NAME': 'mailu',\n    'SQLITE_DATABASE_FILE':'data/main.db',\n    'SQLALCHEMY_DATABASE_URI': 'sqlite:////data/main.db',\n    'SQLALCHEMY_TRACK_MODIFICATIONS': False,\n    # Statistics management\n    'INSTANCE_ID_PATH': '/data/instance',\n    'STATS_ENDPOINT': '0.{}.stats.mailu.io',\n    # Common configuration variables\n    'SECRET_KEY': 'changeMe',\n    'DOMAIN': 'mailu.io',\n    'HOSTNAMES': 'mail.mailu.io,alternative.mailu.io,yetanother.mailu.io',\n    'POSTMASTER': 'postmaster',\n    'TLS_FLAVOR': 'cert',\n    'AUTH_RATELIMIT': '10/minute;1000/hour',\n    'DISABLE_STATISTICS': False,\n    # Mail settings\n    'DMARC_RUA': None,\n    'DMARC_RUF': None,\n    'WELCOME': False,\n    'WELCOME_SUBJECT': 'Dummy welcome topic',\n    'WELCOME_BODY': 'Dummy welcome body',\n    'DKIM_SELECTOR': 'dkim',\n    'DKIM_PATH': '/dkim/{domain}.{selector}.key',\n    'DEFAULT_QUOTA': 1000000000,\n    # Web settings\n    'SITENAME': 'Mailu',\n    'WEBSITE': 'https://mailu.io',\n    'WEB_ADMIN': '/admin',\n    'WEB_WEBMAIL': '/webmail',\n    'WEBMAIL': 'none',\n    'RECAPTCHA_PUBLIC_KEY': '',\n    'RECAPTCHA_PRIVATE_KEY': '',\n    # Advanced settings\n    'PASSWORD_SCHEME': 'PBKDF2',\n    'LOG_LEVEL': 'WARNING',\n    # Host settings\n    'HOST_IMAP': 'imap',\n    'HOST_LMTP': 'imap:2525',\n    'HOST_POP3': 'imap',\n    'HOST_SMTP': 'smtp',\n    'HOST_AUTHSMTP': 'smtp',\n    'HOST_ADMIN': 'admin',\n    'ANTISPAM': 'none',\n    'HOST_ANTISPAM': 'antispam:11334',\n    'WEBMAIL': 'none',\n    'HOST_WEBMAIL': 'webmail',\n    'HOST_WEBDAV': 'webdav:5232',\n    'HOST_REDIS': 'redis',\n    'HOST_FRONT': 'front',\n    'SUBNET': '192.168.203.0/24',\n    'POD_ADDRESS_RANGE': None\n}\n\nclass ConfigManager(dict):\n    \"\"\" Naive configuration manager that uses environment only\n    \"\"\"\n\n    DB_TEMPLATES = {\n        'sqlite': 'sqlite:////{SQLITE_DATABASE_FILE}',\n        'postgresql': 'postgresql://{DB_USER}:{DB_PW}@{DB_HOST}/{DB_NAME}',\n        'mysql': 'mysql://{DB_USER}:{DB_PW}@{DB_HOST}/{DB_NAME}'\n    }\n\n    def __init__(self):\n        self.config = dict()\n\n    def get_host_address(self, name):\n        # if MYSERVICE_ADDRESS is defined, use this\n        if '{}_ADDRESS'.format(name) in os.environ:\n            return os.environ.get('{}_ADDRESS'.format(name))\n        # otherwise use the host name and resolve it\n        return system.resolve_address(self.config['HOST_{}'.format(name)])\n\n    def resolve_hosts(self):\n        self.config[\"IMAP_ADDRESS\"] = self.get_host_address(\"IMAP\")\n        self.config[\"POP3_ADDRESS\"] = self.get_host_address(\"POP3\")\n        self.config[\"AUTHSMTP_ADDRESS\"] = self.get_host_address(\"AUTHSMTP\")\n        self.config[\"SMTP_ADDRESS\"] = self.get_host_address(\"SMTP\")\n        self.config[\"REDIS_ADDRESS\"] = self.get_host_address(\"REDIS\")\n        if self.config[\"WEBMAIL\"] != \"none\":\n            self.config[\"WEBMAIL_ADDRESS\"] = self.get_host_address(\"WEBMAIL\")\n        if self.config[\"ANTISPAM\"] != \"none\":\n            self.config[\"ANTISPAM_ADDRESS\"] = self.get_host_address(\"ANTISPAM\")\n\n    def __coerce_value(self, value):\n        if isinstance(value, str) and value.lower() in ('true','yes'):\n            return True\n        elif isinstance(value, str) and value.lower() in ('false', 'no'):\n            return False\n        return value\n\n    def init_app(self, app):\n        self.config.update(app.config)\n        # get environment variables\n        self.config.update({\n            key: self.__coerce_value(os.environ.get(key, value))\n            for key, value in DEFAULT_CONFIG.items()\n        })\n        self.resolve_hosts()\n\n        # automatically set the sqlalchemy string\n        if self.config['DB_FLAVOR']:\n            template = self.DB_TEMPLATES[self.config['DB_FLAVOR']]\n            self.config['SQLALCHEMY_DATABASE_URI'] = template.format(**self.config)\n\n        self.config['RATELIMIT_STORAGE_URL'] = 'redis://{0}/2'.format(self.config['REDIS_ADDRESS'])\n        self.config['QUOTA_STORAGE_URL'] = 'redis://{0}/1'.format(self.config['REDIS_ADDRESS'])\n        # update the app config itself\n        app.config = self\n\n    def setdefault(self, key, value):\n        if key not in self.config:\n            self.config[key] = value\n        return self.config[key]\n\n    def get(self, *args):\n        return self.config.get(*args)\n\n    def keys(self):\n        return self.config.keys()\n\n    def __getitem__(self, key):\n        return self.config.get(key)\n\n    def __setitem__(self, key, value):\n        self.config[key] = value\n\n    def __contains__(self, key):\n        return key in self.config\n", "path": "core/admin/mailu/configuration.py"}]}