File: lib.php

package info (click to toggle)
moodle 1.6.3-2%2Betch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 37,172 kB
  • ctags: 51,688
  • sloc: php: 231,916; sql: 5,631; xml: 2,688; sh: 1,185; perl: 638; makefile: 48; pascal: 36
file content (50 lines) | stat: -rw-r--r-- 1,606 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?PHP  // $Id: lib.php,v 1.2 2006/01/16 05:25:37 martinlanghoff Exp $
       // Authentication by looking up a RADIUS server
       // Contributed by Clive Gould <clive@ce.bromley.ac.uk>

function auth_user_login ($username, $password) {
    // Returns true if the username and password work
    // and false if they are wrong or don't exist.
    
    require_once 'Auth/RADIUS.php';
    
    global $CFG;
    
    // Added by Clive on 7th May for test purposes
    // printf("Username: $username <br>");
    // printf("Password: $password <br>");
    // printf("auth_radiushost: $CFG->auth_radiushost <br>");
    // printf("auth_radiusnasport: $CFG->auth_radiusnasport <br>");
    // printf("auth_radiussecret: $CFG->auth_radiussecret <br>");
    
    $rauth = new Auth_RADIUS_PAP($username, $password);
    $rauth->addServer($CFG->auth_radiushost, $CFG->auth_radiusnasport, $CFG->auth_radiussecret);
    
    if (!$rauth->start()) {
        printf("Radius start: %s<br>\n", $rauth->getError());
        exit;
    }
    
    $result = $rauth->send();
    if (PEAR::isError($result)) {
        printf("Radius send failed: %s<br>\n", $result->getMessage());
        exit;
    } else if ($result === true) {
        // printf("Radius Auth succeeded<br>\n");
        return true;
    } else {
        // printf("Radius Auth rejected<br>\n");
        return false;
    }
    
    // get attributes, even if auth failed
    if (!$rauth->getAttributes()) {
        printf("Radius getAttributes: %s<br>\n", $rauth->getError());
    } else {
        $rauth->dumpAttributes();
    }
    
    $rauth->close();
}
?>