3

We have a non-Drupal intranet system built on php/mySQL. We're adding a Drupal install to handle some social functions, and would like (if possible) to not duplicate all of our login information. Is there a module (or technique) that would let us authenticate against our existing users table, rather than needing to create separate user records in the new Drupal install?

I did find this, but it's been abandoned for 6 years, so I don't know how relevant it is anymore.

We have not started the new install yet, so either 6 or 7 is possible - if there's a module that would work for only 6, we're perfectly willing to do that.

2 Answers 2

2

My suggestion would be to take a look at LDAP integration or Lightweight Directory Access Protocol modules to see how they handle authentication.

My recollection is that they hook_form_alter the user_login form to add a new validation function that calls out to the LDAP server if Drupal authentication fails. You should be able to do this for your own authentication. We modeled a custom authentication on this method, but I don't recall all of the details.

Just remember that you want to use the external authentication in addition to and not instead of Drupal authenticaion so you don't lock out any admins if/when your other site is down.

4
  • OK, I looked, and I think perhaps I didn't explain properly what I want to do. I'm not looking for a solution that will let users log in to Drupal with usernames from another database. What I want is for users who are already logged in to our other system to not have to log in at all to the Drupal database, since their username will be stored as a session variable. Any way to bypass the login form entirely?
    – EmmyS
    May 10, 2012 at 20:38
  • You are looking for what is called "single sign-on". I think there are a few questions here about that.
    – mpdonadio
    May 10, 2012 at 20:47
  • Thanks, I'll take a look. From what I recall hearing, single sign-on usually involves LDAP, which we're not using. But maybe there's something else.
    – EmmyS
    May 11, 2012 at 13:57
  • Two different things. LDAP just means a centralized authentication system. SSO means that your login session gets carried over to different systems.
    – mpdonadio
    May 11, 2012 at 14:30
1

Read this link on how to connect to multiple dB's with Drupal: http://drupal.org/node/18429

Then... You need first to add another database connection in sites/default/setting.php You will find your primary connection, and add another as stated in config file:

  • Database configuration format:
    • @code
    • $databases['default']['default'] = array(
    • 'driver' => 'mysql',
    • 'database' => 'databasename',
    • 'username' => 'username',
    • 'password' => 'password',
    • 'host' => 'localhost',
    • 'prefix' => '',
    • );
    • $databases['default']['default'] = array(
    • 'driver' => 'pgsql',
    • 'database' => 'databasename',
    • 'username' => 'username',
    • 'password' => 'password',
    • 'host' => 'localhost',
    • 'prefix' => '',
    • );
    • $databases['default']['default'] = array(
    • 'driver' => 'sqlite',
    • 'database' => '/path/to/databasefilename',
    • ); Then you can easily acess data from that another database, for example, executing script in node.tpl.php like this:

db_set_active('my_database'); $artikal = db_select('my_table', 'n') ->fields('n') ->condition('my_row', $my_variable, '=') ->execute() ->fetchAssoc(); and after acessing your other database, get back to default with

db_set_active('default');

db_set_active

5 database.inc db_set_active($name = 'default') 6 database.inc db_set_active($name = 'default') 7 database.inc db_set_active($key = 'default') 8 database.inc db_set_active($key = 'default') Sets a new active database.

Parameters $key: The key in the $databases array to set as the default database.

Return value The key of the formerly active database.

Related topics Database abstraction layer Allow the use of different database servers using the same code base. 2 calls to db_set_active()

File includes/database/database.inc, line 2522 Core systems for the database layer. Code function db_set_active($key = 'default') { return Database::setActiveConnection($key); }

4
  • I've actually changed jobs and no longer work with Drupal, but will pass this on to my replacement in case they're still trying to get this going.
    – EmmyS
    Dec 3, 2012 at 16:09
  • @EmmyS ... looking at your profile (and recent new questions), it seems like you're "back"! No? Aug 17, 2015 at 8:20
  • @Pierre.Vriens - just for a single part-time project.
    – EmmyS
    Aug 18, 2015 at 16:06
  • That's how it starts ... again, right? Because you "had" to, or you "wanted" to? Whatever the reason was: you did remember Drupal.SE also ...! Aug 18, 2015 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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