I was having a problem where if a user logs in with invalid credentials using the form-based login, authentication would be performed twice. Why this happens is complicated, and has to do with additional plugins that implement IRequestFilter, so I won't go into the details right now, but am willing to if necessary.
Regardless, I don't think LoginModule._remote_user() (and by extension AccountManager.check_password()) should be called more than once in the request. This is especially a problem in my case, where users who're authenticating against an LDAP server are being locked out of their accounts due to invalid logins much faster than they should.
This was my solution--in my setup the only thing that should be setting the 'REMOTE_USER' environment variable is the account manager plugin. Though maybe a more flexible approach would be desired:
Index: web_ui.py
===================================================================
--- web_ui.py (revision 6688)
+++ web_ui.py (working copy)
@@ -437,7 +437,8 @@
def authenticate(self, req):
if req.method == 'POST' and req.path_info.startswith('/login'):
- req.environ['REMOTE_USER'] = self._remote_user(req)
+ if 'REMOTE_USER' not in req.environ:
+ req.environ['REMOTE_USER'] = self._remote_user(req)
return auth.LoginModule.authenticate(self, req)
authenticate = if_enabled(authenticate)