Closed (fixed)
Project:
Services
Version:
7.x-3.x-dev
Component:
Code
Priority:
Critical
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
16 Feb 2014 at 22:31 UTC
Updated:
5 Mar 2015 at 18:46 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
tyler.frankenstein commentedHere's a patch for @scotthooker's suggestion.
Related issue: #2195489: PHP Parse error: syntax error, unexpected ':' in user_resource.inc on line 286
Comment #2
yaworsk commentedi dont think this patch works. $account['pass'] is actually an array so think it should be:
'pass1' => isset($account['pass']) ? $account['pass']['pass1'] : '',
'pass2' => isset($account['pass']) ? $account['pass']['pass2'] : '',
patch attached.
Comment #3
scotthooker commentedPretty sure
$form_state['values']['pass'] = array(
'pass1' => isset($account['pass']) ? $account['pass'] : '',
'pass2' => isset($account['pass']) ? $account['pass'] : '',
);
works
Comment #4
yaworsk commentedwhen i dump $account, $account['pass'] is an array so we can't get the actual value if we just use ? $account['pass']. Doing so results in a validation error for me with the following warning:
Warning: trim() expects parameter 1 to be string, array given in password_confirm_validate() (line 2881 of /var/www/dev/includes/form.inc).
Comment #5
scotthooker commentedI see. I'll test and update the ticket.
Comment #6
TangMonk commentedIn 7.x-3.7, It try to use above patch, But still not work.
$ curl -H 'Content-type: application/json' -d '{"name":"u10", "pass": "123","mail": "user@a.om"}' http://localhost/test/api/user/registerreturn me ok:
{"uid":"11","uri":"http://drupal/daxuebao/api/user/11"}But I try to login:
$ curl -H 'Content-type: application/json' -d '{"username":"u10", "password": "123","mail": "user@a.om"}' http://localhost/test/api/user/loginIt alert me :
["Wrong username or password."]Comment #7
tyler.frankenstein commentedWith the patch in comment #1, I just confirmed a user registration (with password) will work properly if you pass JSON like this:
I'd like to point out that passwords are collected on user registration, only when e-mail verification is disabled.
@yaworsk (regarding patch #2), if $account['pass'] is an array for you, then I'm pretty sure that you must be passing an array/object to it, when a string should be passed (hence the warning message in #4).
@TangMonk (#6), your registration call should work if you use patch #1.
Comment #8
yaworsk commented@tyler - good point about passing the array. I've seen multiple implementations of this. I was passing
"pass":{
"pass1":"abcdef",
"pass2":"abcdef"
}
to match the actual form submission where you have to enter and confirm the password. I assume that is how this module is intended to work as the code is setting pass1 and pass2... if there is a mistake during the api call and we are just passing in the password via a string one time, that could result in problems for the end user, right?
Comment #9
tyler.frankenstein commented@yaworsk, it really depends on how the Services team wants to handle this "bug". As far as I recall, the Services call always just collected one password, then used that single password to fill in the 2 password form fields, behind the scenes.
So I think passing in one password is OK, but that puts an assumption on consumers of the service, to make sure their users provide two identical passwords, before passing off the single password to services.
We'll have to wait for a Services team member to chime in on this one.
Comment #10
yaworsk commented@tyler, yeah my thinking exactly. Thanks!
Comment #11
remco75 commentedthe patch works for me. nice work!
Comment #12
Tom83 commentedPatch from #2 works for me. Thanks for finding the issue guys! I was searching for problems in different places!
Comment #13
tyler.frankenstein commentedI don't think patch #2 will be backwards compatable.
Take a look at this commit:
http://drupalcode.org/project/services.git/commitdiff/c8e9ac50bfcce574b3...
According to the commit diff above, we used to always just pass one password string to the service resource.
Patch #2 assumes we will be passing an array/object with two strings, which will break current consumption of the resource.
I'm not on the Services team so I'm not entirely sure this is valid, or if there is a Change Record in place for this. But from my experience, the commit diff linked above did introduce this "bug" for current consumers.
Patch #1 fixes it for current consumers.
Comment #14
yaworsk commentedyeah, i'd defer to the services team. I'm of two minds, we could easily update the patch to check to see if the array is being passed in and if not, then just use the one value twice. However, core uses a password and a confirmation field and i'd recommend that both be actually passed into the call to mimic that core functionality. imho don't think it is a good idea to introduce a work around in services which essentially provides backward compatibility that's not actually inline with core...
Comment #15
kylebrowning commentedWe can use the versions system built into services to provide a new version with new array method, and fix the old version so it does not set a password of 1.
http://drupalcode.org/project/services.git/blob/refs/heads/7.x-3.x:/docs...
Comment #16
kylebrowning commentedComment #17
abhijit.shingate commentedAwesome!! patch 2 worked for me.
Thank you so much peter yaworski !!
Comment #18
tyler.frankenstein commented@kylebrowning, since the old and new versions of the User Register resouce proposed here both accept an array as its data, I didn't see a way to create a new version of the resource (http://cgit.drupalcode.org/services/tree/docs/services.versions.api.php?...).
I've instead modified the callback to handle a single string for legacy purposes (http://cgit.drupalcode.org/services/diff/?id=c8e9ac50bfcce574b39564a0bfe...), and to handle an array of strings for new age purposes.
Comment #20
evanbarter commentedSetting to RTBC, #18 fixes my use case of passing in a password string and the array handling stuff LGTM as well.
Comment #22
alex.skrypnyk#18 fixes for me as well.
Comment #23
kylebrowning commentedComment #25
buggi commentedIn using Recent version of services (services-7.x-3.10), there is a bug in password.
I sent this json data to druapl.
{"name":"buggi",
"mail":"buggi@gmail.com",
"pass":{ "pass1":"a111","pass2":"a111"},
"status":"1"
}
User was created but login was failed .
error message : Wrong username or password. 401
I searched codes in user_resource.inc
$pass1 = '';
$pass2 = '';
if (isset($account['pass'])) {
// For legacy usage, passwords come in as a single string. To match the
// actual form state value keys used by Drupal, we also can collect two
// passwords via an array.
if (is_array($account['pass'])) {
$pass1 = $account['pass']['pass1'];
$pass2 = $account['pass']['pass2'];
}
else {
$pass1 = $account['pass'];
$pass2 = $account['pass'];
}
}
$form_state['values']['pass'] = array(
'pass1' => $pass1,
'pass2' => $pass2
);
What problems ?
Comment #26
kylebrowning commentedWE have a test that checks this, so I'm not sure what you're referring to.
Comment #27
alex.skrypnykReopening this issue as the patch has not been committed.
Comment #28
marcingy commentedThis was fixed as part of the security release a few months ago