More authentication possibilities
[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->auth_dbhost   = "localhost";
8 $CFG->auth_dbtype   = "mysql";     // (postgresql, etc)
9 $CFG->auth_dbname   = "authtest";
10 $CFG->auth_dbtable  = "users";
11 $CFG->auth_dbuser   = "user";
12 $CFG->auth_dbpass   = "pass";
13 $CFG->auth_dbfielduser   = "user";
14 $CFG->auth_dbfieldpass   = "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->auth_dbtype);          
23     $authdb = &ADONewConnection();         
24     $authdb->PConnect($CFG->auth_dbhost,$CFG->auth_dbuser,$CFG->auth_dbpass,$CFG->auth_dbname); 
27     $rs = $authdb->Execute("SELECT * FROM $CFG->auth_dbtable 
28                             WHERE $CFG->auth_dbfielduser = '$username' 
29                               AND $CFG->auth_dbfieldpass = '$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 ?>