]> git.mjollnir.org Git - moodle.git/commitdiff
More authentication possibilities
authormoodler <moodler>
Fri, 15 Nov 2002 08:42:40 +0000 (08:42 +0000)
committermoodler <moodler>
Fri, 15 Nov 2002 08:42:40 +0000 (08:42 +0000)
auth/README
auth/db/lib.php
auth/imap/lib.php [new file with mode: 0644]

index c054c1e99d4e1e8e901e1576816b5c1a4559b9f7..a1bdff48677a95c78f82c088b02e4c2a2ca5ae51 100644 (file)
@@ -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
index 5cee2d66fe2700d4fccc662805b183e94beb6dda..0e9677e1f9f1ba3401667e063eab085c21b76c2c 100644 (file)
@@ -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 (file)
index 0000000..a2e7c8e
--- /dev/null
@@ -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;
+    }
+}
+
+
+?>