Permalink
Browse files

More authentication possibilities

  • Loading branch information...
1 parent dce48fc commit d1b4e172675f74f630e1d5b8939af7f4f60ea0d7 moodler committed Nov 15, 2002
Showing with 75 additions and 14 deletions.
  1. +19 −1 auth/README
  2. +13 −13 auth/db/lib.php
  3. +43 −0 auth/imap/lib.php
View
@@ -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
View
@@ -4,29 +4,29 @@
// 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
// and false if they are wrong or don't exist.
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;
View
@@ -0,0 +1,43 @@
+<?PHP // $Id$
+ // Authentication by looking up an IMAP server
+
+// This code is completely untested so far - I'm just jotting down ideas ...
+// Looks like it should work though ...
+
+$CFG->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;
+ }
+}
+
+
+?>

0 comments on commit d1b4e17

Please sign in to comment.