I wrote a module to allow users to login using credentials stored outside of the Drupal users table. It is loosely based off Darren Mothersele's article with one defining difference being that the client needed users to be able to login with a password being from 1 of 2 possible fields.

Most of the external users can login w/o an issue. There are a few usernames in the external table that can not login. Not only do they get a failed attempt but I get some nice php errors as well:

in_array() [<a href='function.in-array'>function.in-array</a>]: Wrong datatype for second argument in sites/all/themes/zen/template.php on line 247.
line 247: 
$vars['is_admin'] = in_array('administrative user', $user->roles);

Invalid argument supplied for foreach() in sites/all/modules/google_analytics/googleanalytics.module on line 564.
line 564:
foreach (array_keys($account->roles) as $rid) {
      // Is the current user a member of one role enabled for tracking?
      if (isset($roles[$rid]) && $rid == $roles[$rid]) {
        // Current user is a member of a role that should be tracked.
        $enabled = TRUE;
        break;
      }
    }

array_merge() [<a href='function.array-merge'>function.array-merge</a>]: Argument #2 is not an array in /var/www/html/prod-iar/modules/block/block.module on line 647.
line 645-647:
    $rids = array_keys($user->roles);
    $placeholders = implode(',', array_fill(0, count($rids), '%d'));
    $result = db_query("SELECT DISTINCT b.* FROM {blocks} b LEFT JOIN {blocks_roles} r ON b.module = r.module AND b.delta = r.delta WHERE b.theme = '%s' AND b.status = 1 AND (r.rid IN ($placeholders) OR r.rid IS NULL) ORDER BY b.region, b.weight, b.module", array_merge(array($theme_key), $rids));

Those lines of course cause a few more errors including mysql errors from includes/database.mysqli.inc. Then after I get the "Login attempt failed for username" message followed by a "External load by username using module member_auth." then some user module errors from line 377-379 and again a failed mysql query error:

  if (!isset($perm[$account->uid])) {
    $rids = array_keys($account->roles);
    $placeholders = implode(',', array_fill(0, count($rids), '%d'));
    $result = db_query("SELECT DISTINCT(p.perm) FROM {role} r INNER JOIN {permission} p ON p.rid = r.rid WHERE r.rid IN ($placeholders)", $rids);
    $perm[$account->uid] = '';
    while ($row = db_fetch_object($result)) {
      $perm[$account->uid] .= "$row->perm, ";
    }
  }

So I am at loss. To me, it seems all centered around roles but my Drupal knowledge regarding user authentication is left wanting. As far as I can tell the entries in the database for the failing users are not the issue. I have swapped out the fields with known working records and still get failures. Any guidance on where I should be looking to further debug this issue would be great.

Thanks in advance,
--
Dan

Comments

dan.blah’s picture

this ended up being caused by stale data in the authmap table where records existed that didnt exist in the users table.