I've been seeing an error in my PHP logs whenever the user.login() service is called and the username/password is invalid.
Looking at the code in user_service.inc, the login function performs user_authenticate() and immediately assigns the results to the global $user object. When the login is valid, this behavior is fine. But when user_authenticate() fails (i.e. invalid username or password), the global $user object becomes NULL. This causes errors for any other modules that have code that runs after the user.login() call because they expect a valid $user object, even if it's just an Anonymous user.
Attached is a patch that checks the return value of user_authenticate() before assigning it to the global $user object.
| Comment | File | Size | Author |
|---|---|---|---|
| user_services-anon_fix.patch | 1.12 KB | hargobind |
Comments
Comment #1
kylebrowning commentedLooks good. Someone else should review once before I commit.
Comment #2
dave reidIf this is for D6, then the user_authenticate() function itself assigns the global user variable and performs hook_user('login') for you when it is successful, so I'm seeing duplication of code.
Comment #4
marcingy commentedAfter reading #2 this is a won't fix as the global user has already been updated to value loaded so this patch changes nothing.
Comment #5
dave reidWell there's some things still worth fixing here - like not actually assigning $user to the result of user_authenticate() and removing the invocation of hook_user('login')
Comment #6
marcingy commentedbumping version
Comment #7
kylebrowning commentedThis is actually already fixed in the 3.x source and the module invoke is required in 7 because user_authenticate does not invoke that.
Comment #8
dave reidOK, then I'm not sure why this still wouldn't apply to 6.x-3.x?
Comment #9
kylebrowning commentedFixed in 6.x-3.x, thanks Dave