More authentication possibilities
[moodle.git] / auth / imap / lib.php
CommitLineData
d1b4e172 1<?PHP // $Id$
2 // Authentication by looking up an IMAP server
3
4// This code is completely untested so far - I'm just jotting down ideas ...
5// Looks like it should work though ...
6
7$CFG->auth_imaphost = "localhost";
8$CFG->auth_imapport = "143"; // 143, 993, 100, 119
9$CFG->auth_imaptype = "imap"; // imap, imapssl, pop3, nntp
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;
25 case "pop3":
26 $host = "{$CFG->auth_imaphost:$CFG->auth_imapport/pop3}INBOX";
27 break;
28 case "nntp":
29 $host = "{$CFG->auth_imaphost:$CFG->auth_imapport/nntp}comp.test";
30 break;
31 }
32
33 if ($connection = imap_open($host, $username, $password)) {
34 imap_close($connection);
35 return true;
36
37 } else {
38 return false;
39 }
40}
41
42
43?>