Login failing on second attempt
I am getting a lot of login failures on my second attempt to login.
After some digging around, I am finding SMF when it detects a failed login is destroying the session, which is causing the server to send a new cookie.
To reproduce:
- Open Chrome developer tools (or equivalent)
- Navigate to your SMF login page and note the cookie in the request headers, also note the response headers do not contain any.
- Do a failed login (such as a bad password)
- Note the request headers have the original cookie, note that response headers are now sending back a new cookie and SMF cookie.
This causes logins to fail because the session checks now fail. Somewhere along the line we are doing this on failed logins. I haven't been able to track that down yet, but need to open this to make sure we look into fixing that yet.
More tracking, its because of setLoginCookie
It appears to destroy the session and recreate the new one. While it attempts to save the $_SESSION data, I don't think this is happening.
As far as I remember, this has always been the behaviour. The only new thing in 2.1 is the token (that is used to hash the pair username/password),
/me guesses the problem is the token is not recreated soon enough or is recreated twice or so.
The error is not about a token mismatch but about session check failing. The problem seems to be because the cookie has changed because a new session id was set.
Okay, I tried to really replicate this and this is how I can replicate it:
- action=login
- insert wrong password
- insert wrong password (a second time)
- insert correct password => reminder instead of login
Now, if I disable javascript the login happens correctly. That means the problem is likely in the hashing. Since in 2.1 the hashing is using a token to make the hashed code POST'ed unique I really feel this is a token "mismatch" (but not in the sense that validateToken fails, because in that case validateToken is not involved at all).
Hmm, I can easily reproduce it on the second failed login attempt. It always gives me a session error and when I check it out (dumping out data), I see my php session id has changed.
I wonder why we even recreate a new session and cookie. Is this even necessary?
I think this is the same or a similar issue to #447
This was mostly caused by not doing the proper token verification. Login does those. This seems to be related to some session related issue. If I disable tokens on the login screen this still happens. Which leads me to believe its apart of the session issues still.
Its nice whoever setup login tokens made it fairly easy to disable, no template edits required.
I think this one has been fixed somewhere along the way?
Most likely.