/** * Authenticate * * @param string Username * @param string Password * @return bool true on success, false on reject */ function fetchData($username, $password, $challenge = null) { $this->log('Auth_Container_RADIUS::fetchData() called.', AUTH_LOG_DEBUG); switch ($this->authtype) { case 'CHAP_MD5': case 'MSCHAPv1': if (isset($challenge)) { $this->radius->challenge = $challenge; $this->radius->chapid = 1; $this->radius->response = pack('H*', $password); } else { require_once 'Crypt/CHAP.php'; $classname = 'Crypt_' . $this->authtype; $crpt = new $classname(); $crpt->password = $password; $this->radius->challenge = $crpt->challenge; $this->radius->chapid = $crpt->chapid; $this->radius->response = $crpt->challengeResponse(); } break; case 'MSCHAPv2': require_once 'Crypt/CHAP.php'; $crpt = new Crypt_MSCHAPv2(); $crpt->username = $username; $crpt->password = $password; $this->radius->challenge = $crpt->authChallenge; $this->radius->peerChallenge = $crpt->peerChallenge; $this->radius->chapid = $crpt->chapid; $this->radius->response = $crpt->challengeResponse(); break; default: $this->radius->password = $password; break; } $this->radius->username = $username; $this->radius->putAuthAttributes(); $result = $this->radius->send(); if (PEAR::isError($result)) { return false; } $this->radius->getAttributes(); // just for debugging // $this->radius->dumpAttributes(); return $result; }
switch ($type) { case 'CHAP_MD5': case 'MSCHAPv1': $classname = 'Crypt_' . $type; $crpt = new $classname(); $crpt->password = $password; $rauth->challenge = $crpt->challenge; $rauth->chapid = $crpt->chapid; $rauth->response = $crpt->challengeResponse(); $rauth->flags = 1; // If you must use deprecated and weak LAN-Manager-Responses use this: // $rauth->lmResponse = $crpt->lmChallengeResponse(); // $rauth->flags = 0; break; case 'MSCHAPv2': $crpt = new Crypt_MSCHAPv2(); $crpt->username = $username; $crpt->password = $password; $rauth->challenge = $crpt->authChallenge; $rauth->peerChallenge = $crpt->peerChallenge; $rauth->chapid = $crpt->chapid; $rauth->response = $crpt->challengeResponse(); break; default: $rauth->password = $password; break; } if (!$rauth->start()) { printf("Radius start: %s<br>\n", $rauth->getError()); exit; }