Nothing missing, just needs testing and debugging
[moodle.git] / auth / imap / lib.php
CommitLineData
d1b4e172 1<?PHP // $Id$
d5b94ef4 2 // Authentication by looking up an IMAP, POP or NNTP server
d1b4e172 3
d5b94ef4 4// This code is completely untested so far - IT NEEDS TESTERS!
d1b4e172 5// Looks like it should work though ...
6
d17bdf2b 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
d1b4e172 10
11
12function 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.
15
16 global $CFG;
17
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;
d17bdf2b 25 case "imapcert":
26 $host = "{$CFG->auth_imaphost:$CFG->auth_imapport/imap/ssl/novalidate-cert}INBOX";
27 break;
d1b4e172 28 case "pop3":
29 $host = "{$CFG->auth_imaphost:$CFG->auth_imapport/pop3}INBOX";
30 break;
d17bdf2b 31 case "pop3cert":
32 $host = "{$CFG->auth_imaphost:$CFG->auth_imapport/pop3/ssl/novalidate-cert}INBOX";
33 break;
d1b4e172 34 case "nntp":
d17bdf2b 35 $host = "{$CFG->auth_imaphost:$CFG->auth_imapport/nntp}";
d1b4e172 36 break;
37 }
38
d17bdf2b 39 if ($connection = imap_open($host, $username, $password, OP_HALFOPEN)) {
d1b4e172 40 imap_close($connection);
41 return true;
42
43 } else {
44 return false;
45 }
46}
47
48
49?>