First version of code to authenticate against external database.
[moodle.git] / auth / db / lib.php
1 <?PHP  // $Id$
2        // Authentication by looking up an external database table
4 // This code is completely untested so far - I'm just jotting down ideas ...
5 // Looks like it should work though ...
7 $CFG->authdbhost   = "localhost";
8 $CFG->authdbtype   = "mysql";     // (postgresql, etc)
9 $CFG->authdbname   = "authtest";
10 $CFG->authdbtable  = "users";
11 $CFG->authdbuser   = "user";
12 $CFG->authdbpass   = "pass";
13 $CFG->authdbfielduser   = "user";
14 $CFG->authdbfieldpass   = "pass";
16 function auth_user_login ($username, $password) {
17 // Returns true if the username and password work
18 // and false if they are wrong or don't exist.
20     global $CFG;
22     ADOLoadCode($CFG->authdbtype);          
23     $authdb = &ADONewConnection();         
24     $authdb->PConnect($CFG->authdbhost,$CFG->authdbuser,$CFG->authdbpass,$CFG->authdbname); 
27     $rs = $authdb->Execute("SELECT * FROM $CFG->authdbtable 
28                             WHERE $CFG->authdbfielduser = '$username' 
29                               AND $CFG->authdbfieldpass = '$password' ");
30     if (!$rs) {
31         notify("Could not connect to the specified authentication database...");
32         return false;
33     }
35     if ( $rs->RecordCount() ) {
36         return true;
37     } else {
38         return false;
39     }
40 }
43 ?>