Reject Specific Database PostgreSQL User Authentication
If those two databases are on the same cluster (beware of the PostgreSQL terminology, it's a name for an instance or installation or whatever you want), then you cannot prevent the users from logging in.  All databases on a single cluster share the same users:


  Database roles are conceptually completely separate from operating system users. In practice it might be convenient to maintain a correspondence, but this is not required. Database roles are global across a database cluster installation (and not per individual database). 


As Neil McGuigan pointed out in his comment, this is not completely true - one can set db_user_namespace to have database specific user names.  I don't recommend using this, the reason is in the documentation:


  Note: This feature is intended as a temporary measure until a complete solution is found. At that time, this option will be removed.


Also, if user B knows the password of a@databasea, this cannot prevent him from logging in.

What you can do, however, is preventing user A from doing anything in databaseB by revoking every permission there might be, especially connecting to a database.  The background is that logging in to a cluster is not the same thing as connecting to a database.  Preventing the latter is easy:

REVOKE ALL ON DATABASE databaseb FROM a; -- ALL means CONNECT, too


Please note that pg_hba.conf does its work also on the database level, so you can disallow connections there, too:

# TYPE  DATABASE        USER            CIDR-ADDRESS            METHOD
host    databasea       a               10.228.116.0/24         md5
host    databaseb       b               10.228.116.0/24         md5