More authentication possibilities
This commit is contained in:
+19
-1
@@ -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
|
||||
|
||||
+13
-13
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user