Nothing missing, just needs testing and debugging
[moodle.git] / auth / db / lib.php
CommitLineData
dce48fc8 1<?PHP // $Id$
2 // Authentication by looking up an external database table
3
d5b94ef4 4// This code is completely untested so far - IT NEEDS TESTERS!
dce48fc8 5// Looks like it should work though ...
6
d1b4e172 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";
dce48fc8 15
16function 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.
19
20 global $CFG;
21
d1b4e172 22 ADOLoadCode($CFG->auth_dbtype);
dce48fc8 23 $authdb = &ADONewConnection();
d1b4e172 24 $authdb->PConnect($CFG->auth_dbhost,$CFG->auth_dbuser,$CFG->auth_dbpass,$CFG->auth_dbname);
dce48fc8 25
26
d1b4e172 27 $rs = $authdb->Execute("SELECT * FROM $CFG->auth_dbtable
28 WHERE $CFG->auth_dbfielduser = '$username'
29 AND $CFG->auth_dbfieldpass = '$password' ");
dce48fc8 30 if (!$rs) {
31 notify("Could not connect to the specified authentication database...");
32 return false;
33 }
34
35 if ( $rs->RecordCount() ) {
36 return true;
37 } else {
38 return false;
39 }
40}
41
42
43?>