cdf3161d6de7de92ce57e0096108fff50d7032ee
[moodle.git] / auth / imap / lib.php
1 <?PHP  // $Id$
2        // Authentication by looking up an IMAP server
4 // This code is completely untested so far - I'm just jotting down ideas ...
5 // Looks like it should work though ...
7 $CFG->auth_imaphost   = "127.0.0.1";  // Should be IP number
8 $CFG->auth_imaptype   = "imap";       // imap, imapssl, imapcert, pop3, pop3cert, nntp
9 $CFG->auth_imapport   = "143";        // 143, 993, 100, 119
12 function auth_user_login ($username, $password) {
13 // Returns true if the username and password work
14 // and false if they are wrong or don't exist.
16     global $CFG;
18     switch ($CFG->auth_imaptype) {
19         case "imap":
20             $host = "{$CFG->auth_imaphost:$CFG->auth_imapport}INBOX";
21         break;
22         case "imapssl":
23             $host = "{$CFG->auth_imaphost:$CFG->auth_imapport/imap/ssl}INBOX";
24         break;
25         case "imapcert":
26             $host = "{$CFG->auth_imaphost:$CFG->auth_imapport/imap/ssl/novalidate-cert}INBOX";
27         break;
28         case "pop3":
29             $host = "{$CFG->auth_imaphost:$CFG->auth_imapport/pop3}INBOX";
30         break;
31         case "pop3cert":
32             $host = "{$CFG->auth_imaphost:$CFG->auth_imapport/pop3/ssl/novalidate-cert}INBOX";
33         break;
34         case "nntp":
35             $host = "{$CFG->auth_imaphost:$CFG->auth_imapport/nntp}";
36         break;
37     }
39     if ($connection = imap_open($host, $username, $password, OP_HALFOPEN)) {
40         imap_close($connection);
41         return true;
43     } else {
44         return false;
45     }
46 }
49 ?>