Multi-domain user login access control E.g. My site has two subdomains : domain_a and domain_b.

And My site has three roles: role_a, role_b, role_c.

I hope:

User with role_a can login domain_a, can't login domain_b.
(When user visit domain_b user status is not logined and not lost domain_a logined status)

User with role_b can login domain_b, can't login domain_a.

User with role_c can login domain_a and domain_b.

Does anyone have any solution?
You have two options:

Domain Access has it figured out

Domain Access module excerpt:


  The Domain Access project is a suite of modules that provide tools for running a group of affiliated sites from one Drupal installation and a single shared database. The module allows you to share users, content, and configurations across a group of sites such as:
  
  
  example.com
  one.example.com
  two.example.com
  my.example.com
  thisexample.com &lt;-- can use any domain string
  example.com:3000 &lt;-- treats non-standard ports as unique
  


Then, you need Domain Roles:


  Allows you to save user roles per domain. Allows a certain user to be just authenticated on one domain and admin on another etc.


You can't totally prevent cross-logins, but you can make user logged in with no permissions at all, except to log out.

If you prefer Multisite approach

You can change the settings for the access to the database that are contained in the settings.php file used by your Drupal site to something similar to the following one (replace the values between brackets with the correct values for your site):

$databases['default']['default'] = array(
  'driver' =&gt; '[Your database engine]',
  'database' =&gt; '[Your database name]',
  'username' =&gt; '[Your username for the access to the database engine]',
  'password' =&gt; '[The password for the access to the database]',
  'host' =&gt; 'localhost',
  'prefix' =&gt; array(
    'default'   =&gt; 'main_',
    'users'     =&gt; 'shared_',
    'sessions'  =&gt; 'shared_',
    'role'      =&gt; 'shared_',
    'authmap'   =&gt; 'shared_',
  ),
  'collation' =&gt; 'utf8_general_ci',
);


Taken from this answer.

Then, in hook_user_login(&amp;$edit, $account) test if user has a role he needs to access given page, and if not, logout him with proper message.