How to prevent login if a condition is not met I am working on a Drupal 6 site (which I did not make and am not in charge of the general IT architecture at this company).

The site is on an intranet and they regularly import all users from an external source to Drupal users. The requirement is to restrict access to a subset of the imported users.

So:
When a user logs in if they are on the authorized list then proceed else deny access

I realize this isn't the most effective way of doing things and I would have done in differently, personally. But I am stuck having to do it this way.

What I have working so far:


I have feeds and data modules to import a CSV of authorized users
I am using hook_user() in my module to check if the user is on the authorized list


the problem:

I have all the above working but I can't figure out a clean way to log the user out or terminate the session when they are not found on the list. When I use this it causes errors:

function mymodule_user($op, &amp;$edit, &amp;$account, $category = NULL) {

  switch ($op) {
    case 'login':
        $strID = $account-&gt;uid;
        $strName = $account-&gt;name;
        if ($strID &lt;&gt; 1) {
            if (!mymodule_checkACL($strName)) {
                global $user;
                $user = array();
            }
        }
    break;
  }


Any better way than this? Sorry if the question seems a little basic, I'm new to this.

Thanks
You can use sess_destroy_uid($account-&gt;uid).

You might also consider blocking users during the import process; this is done by setting the "status" column to 0.