0

In 7.x-3.7 .Using POSTER add-on to post this data to service.

I try to use following command to create an user:

'Content-type: application/json'

'{"name":"u10", "pass": "123","mail": "user@a.om"}'

URL : ".../api/user/register"

return success:

{"uid":"11","uri":"../api/user/11"} But I try to login:

'Content-type: application/json'

'{"username":"u10", "password": "123","mail": "user@a.om"}'

URL : "../api/user/login" It alert me :

["Wrong username or password."]

Please help me.

  • no need to include "mail:"user@a.om"" in json format at user login? – Krishna Mohan Apr 22 '14 at 10:53
2

The code in the login resource is very clear:

...
$uid = user_authenticate($username, $password);

// Emulate drupal native flood control
if (empty($uid) && variable_get('services_flood_control_enabled', TRUE)) {
  _user_resource_flood_control($username);
}

if ($uid) {
  $user = user_load($uid);
  if ($user->uid) {
    user_login_finalize();

    $return = new stdClass();
    $return->sessid = session_id();
    $return->session_name = session_name();
    $return->token = drupal_get_token('services');

    $account = clone $user;

    services_remove_user_data($account);

    $return->user = $account;

    return $return;
  }
}
watchdog('user', 'Invalid login attempt for %username.', array('%username' => $username));
return services_error(t('Wrong username or password.'), 401);

As you can see, the only way you can get the "Wrong username or password" error, is if user_authenticate() (or more specifically user_check_password()) fails.

So you're providing an incorrect username and/or password, as the error suggests. Make sure that your call to /user/register is actually registering the user account on the site, and make login into it manually to make doubly sure.

  • Hi clive, i follow url : drupal.org/node/1447020#Register. But when i login with web ->response: Sorry, unrecognized username or password. when i login with service url response: ["Wrong username or password"]. Can you help me ? – user28320 Apr 22 '14 at 13:14
  • @user28320 - I'm having the same problem. I know that the username/password that I'm using are correct. I'm using an admin with user administration privileges to create the user, but the user I create through services is still not able to log in. I think there is something wrong when the password is set in services. How did you fix your problem? Thanks in advance. – Justine Apr 26 '14 at 18:04
  • 1
    @justin , you can use url : drupal.org/files/issues/user_create-2198005-1.patch . Hope you will successfully. – user28320 Apr 27 '14 at 2:09
  • @user28320 - Thank you so much! Your patch fixed the password so that it's being set now, and I can log in after creating the user. I'm having another issue which is strange, but may be similar. Values for other fields besides username, password and email are not being set if specified. For example, "status", "notify" and "roles" are the fields in question. Did you also have this issue? – Justine Apr 28 '14 at 2:38
  • 1
    hi . you can try to following JSON format to register a new user. {"name":"test","pass":"1234","mail":"test@mail.com","status":"1", "roles":["3","4"]} – user28320 Apr 28 '14 at 7:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.