Closed (fixed)
Project:
Drupal core
Component:
user system
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
19 May 2005 at 20:36 UTC
Updated:
15 Feb 2006 at 12:30 UTC
Jump to comment: Most recent file
When run on php 5 there seems to be bug when the user tries to request a new password and user_pass() is called. The code looks like this:
if ($edit['name'] && !($account = user_load(array('name' => $edit['name'], 'status' => 1)))) {
form_set_error('name', t('Sorry. The username %name is not recognized.', array('%name' => theme('placeholder', $edit['name']))));
}
else if ($edit['mail'] && !($account = user_load(array('mail' => $edit['mail'], 'status' => 1)))) {
form_set_error('mail', t('Sorry. The e-mail address %email is not recognized.', array('%email' => theme('placeholder', $edit['mail']))));
}
But the problem is that user_load() always returns a StdClass even if a user isn't found, so the two checks above never get triggered.
This is my fix to get around this issue. But there is probably a much better way to do it, I don't really understand PHP and my "instanceof" approach kept causing errors.
if ($edit['name'] && (!($account = user_load(array('name' => $edit['name'], 'status' => 1))) || !$account->name)) {
form_set_error('name', t('Sorry. The username %name is not recognized.', array('%name' => theme('placeholder', $edit['name']))));
$account = NULL;
}
else if ($edit['mail'] && (!($account = user_load(array('mail' => $edit['mail'], 'status' => 1))) || !$account->name)) {
form_set_error('mail', t('Sorry. The e-mail address %email is not recognized.', array('%email' => theme('placeholder', $edit['mail']))));
$account = NULL;
}
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | requestNewPasswordBug.patch | 2.47 KB | skeen |
Comments
Comment #1
skeen commentedI found this same issue running cvs on php 5.0.4
Since user->load() returns a new StdClass() when the user is not found the the two checks at the top of user_pass() fail to ever return true. (I think in php4 and empty class is probably treated as a empty array which i think resolves to false?)
my fix was to also check for an attribute of the returned user object which for any true user would always exist (uid).
to organize the function a bit more I moved the elseif block
to the top of the function with the other two if blocks that are also validating user input.
added a few quick comments also.
This is the first time I have ever submitted a patch so I apologize if I screwed this up (constructive criticism is appreciated).
Hope I interpreted the existing code correctly and that you find this patch useful.
Sam Keen
Comment #2
skeen commentedSorry, forgot to set the status to patch
Comment #3
robin monks commentedelseif is else if....amung other things.
Look at the style rules in the handbook.
+1 for the function -1 for the style.
Robin
Comment #4
killes@www.drop.org commentedThis has been fixed in cvs, the 4.6 branch isn't fully working with php 5.0.5+ anyway.
Comment #5
(not verified) commented