From: moodler Date: Fri, 15 Nov 2002 08:42:40 +0000 (+0000) Subject: More authentication possibilities X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=d1b4e172675f74f630e1d5b8939af7f4f60ea0d7;p=moodle.git More authentication possibilities --- diff --git a/auth/README b/auth/README index c054c1e99d..a1bdff4867 100644 --- a/auth/README +++ b/auth/README @@ -39,5 +39,23 @@ ldap - Uses an external LDAP server - if correct, user is logged in - optionally, info is copied from the LDAP database to the Moodle user database - + (see the ldap/README for more details on config etc...) + + +imap - Uses an external IMAP server + + - user logs in using username and password + - these are checked against an IMAP server + - if correct, user is logged in + - if the username doesn't already exist then + a new account is created + + +db - Uses an external database to check username/password + + - user logs in using username and password + - these are checked against an external database + - if correct, user is logged in + - if the username doesn't already exist then + a new Moodle account is created diff --git a/auth/db/lib.php b/auth/db/lib.php index 5cee2d66fe..0e9677e1f9 100644 --- a/auth/db/lib.php +++ b/auth/db/lib.php @@ -4,14 +4,14 @@ // This code is completely untested so far - I'm just jotting down ideas ... // Looks like it should work though ... -$CFG->authdbhost = "localhost"; -$CFG->authdbtype = "mysql"; // (postgresql, etc) -$CFG->authdbname = "authtest"; -$CFG->authdbtable = "users"; -$CFG->authdbuser = "user"; -$CFG->authdbpass = "pass"; -$CFG->authdbfielduser = "user"; -$CFG->authdbfieldpass = "pass"; +$CFG->auth_dbhost = "localhost"; +$CFG->auth_dbtype = "mysql"; // (postgresql, etc) +$CFG->auth_dbname = "authtest"; +$CFG->auth_dbtable = "users"; +$CFG->auth_dbuser = "user"; +$CFG->auth_dbpass = "pass"; +$CFG->auth_dbfielduser = "user"; +$CFG->auth_dbfieldpass = "pass"; function auth_user_login ($username, $password) { // Returns true if the username and password work @@ -19,14 +19,14 @@ function auth_user_login ($username, $password) { global $CFG; - ADOLoadCode($CFG->authdbtype); + ADOLoadCode($CFG->auth_dbtype); $authdb = &ADONewConnection(); - $authdb->PConnect($CFG->authdbhost,$CFG->authdbuser,$CFG->authdbpass,$CFG->authdbname); + $authdb->PConnect($CFG->auth_dbhost,$CFG->auth_dbuser,$CFG->auth_dbpass,$CFG->auth_dbname); - $rs = $authdb->Execute("SELECT * FROM $CFG->authdbtable - WHERE $CFG->authdbfielduser = '$username' - AND $CFG->authdbfieldpass = '$password' "); + $rs = $authdb->Execute("SELECT * FROM $CFG->auth_dbtable + WHERE $CFG->auth_dbfielduser = '$username' + AND $CFG->auth_dbfieldpass = '$password' "); if (!$rs) { notify("Could not connect to the specified authentication database..."); return false; diff --git a/auth/imap/lib.php b/auth/imap/lib.php new file mode 100644 index 0000000000..a2e7c8e59a --- /dev/null +++ b/auth/imap/lib.php @@ -0,0 +1,43 @@ +auth_imaphost = "localhost"; +$CFG->auth_imapport = "143"; // 143, 993, 100, 119 +$CFG->auth_imaptype = "imap"; // imap, imapssl, pop3, nntp + + +function auth_user_login ($username, $password) { +// Returns true if the username and password work +// and false if they are wrong or don't exist. + + global $CFG; + + switch ($CFG->auth_imaptype) { + case "imap": + $host = "{$CFG->auth_imaphost:$CFG->auth_imapport}INBOX"; + break; + case "imapssl": + $host = "{$CFG->auth_imaphost:$CFG->auth_imapport/imap/ssl}INBOX"; + break; + case "pop3": + $host = "{$CFG->auth_imaphost:$CFG->auth_imapport/pop3}INBOX"; + break; + case "nntp": + $host = "{$CFG->auth_imaphost:$CFG->auth_imapport/nntp}comp.test"; + break; + } + + if ($connection = imap_open($host, $username, $password)) { + imap_close($connection); + return true; + + } else { + return false; + } +} + + +?>