⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 login.php

📁 完美的在线教育系统
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php/** * OpenID login method *  * The OpenID login method relies on authentication servers providing a public * URL that can confirm the identity of a person, thus avoiding the spread * use of password transmissions over non-secure lines (for Dokeos, it is a * good way of avoiding password theft) *//** * Initialisation */require_once('openid.conf.php');require_once('openid.lib.php');require_once('xrds.lib.php');function openid_form() {	return '<div class="menusection"><span class="menusectioncaption">'.get_lang('OpenIdAuthentication').'</span><form name="openid_login" method="post"><label for="openid_url">'.get_lang('OpenIDURL').' <a href="main/auth/openid/whatis.php" title="'.get_lang('OpenIDWhatIs').'"><img src="main/img/info3.gif" height="15px;" width="15px;" style="margin-bottom:-3px;"/></a></label><input type="text" id="openid_url" name="openid_url" style="background: url(main/img/openid_small_logo.png) no-repeat; background-color: #fff; background-position: 0 50%; padding-left:18px;" value="http://"></input><input type="submit" name="openid_login" value="'.get_lang('Ok').'" /><br /><br /></form></div>';}/** * The initial step of OpenID authentication responsible for the following: *  - Perform discovery on the claimed OpenID. *  - If possible, create an association with the Provider's endpoint. *  - Create the authentication request. *  - Perform the appropriate redirect. * * @param $claimed_id The OpenID to authenticate * @param $return_to The endpoint to return to from the OpenID Provider */function openid_begin($claimed_id, $return_to = '', $form_values = array()) {  $claimed_id = _openid_normalize($claimed_id);  $services = openid_discovery($claimed_id);  if (count($services) == 0) {    echo 'Sorry, that is not a valid OpenID. Please ensure you have spelled your ID correctly.';    return;  }  $op_endpoint = $services[0]['uri'];  // Store the discovered endpoint in the session (so we don't have to rediscover).  $_SESSION['openid_op_endpoint'] = $op_endpoint;  // Store the claimed_id in the session (for handling delegation).  $_SESSION['openid_claimed_id'] = $claimed_id;  // Store the login form values so we can pass them to  // user_exteral_login later.  $_SESSION['openid_user_login_values'] = $form_values;  // If bcmath is present, then create an association  $assoc_handle = '';  if (function_exists('bcadd')) {    $assoc_handle = openid_association($op_endpoint);  }  // Now that there is an association created, move on  // to request authentication from the IdP  $identity = (!empty($services[0]['delegate'])) ? $services[0]['delegate'] : $claimed_id;  if (isset($services[0]['types']) && is_array($services[0]['types']) && in_array(OPENID_NS_2_0 .'/server', $services[0]['types'])) {    $identity = 'http://openid.net/identifier_select/2.0';  }  $authn_request = openid_authentication_request($claimed_id, $identity, $return_to, $assoc_handle, $services[0]['version']);  if ($services[0]['version'] == 2) {    openid_redirect($op_endpoint, $authn_request);  }  else {    openid_redirect_http($op_endpoint, $authn_request);  }}/** * Completes OpenID authentication by validating returned data from the OpenID * Provider. * * @param $response Array of returned from the OpenID provider (typically $_REQUEST). * * @return $response Response values for further processing with *   $response['status'] set to one of 'success', 'failed' or 'cancel'. */function openid_complete($response) {  // Default to failed response  $response['status'] = 'failed';  if (isset($_SESSION['openid_op_endpoint']) && isset($_SESSION['openid_claimed_id'])) {    _openid_fix_post($response);    $op_endpoint = $_SESSION['openid_op_endpoint'];    $claimed_id = $_SESSION['openid_claimed_id'];    unset($_SESSION['openid_op_endpoint']);    unset($_SESSION['openid_claimed_id']);    if (isset($response['openid.mode'])) {      if ($response['openid.mode'] == 'cancel') {        $response['status'] = 'cancel';      }      else {        if (openid_verify_assertion($op_endpoint, $response)) {          $response['openid.identity'] = $claimed_id;          $response['status'] = 'success';        }      }    }  }  return $response;}/** * Perform discovery on a claimed ID to determine the OpenID provider endpoint. * * @param $claimed_id The OpenID URL to perform discovery on. * * @return Array of services discovered (including OpenID version, endpoint * URI, etc). */function openid_discovery($claimed_id) {  $services = array();  $xrds_url = $claimed_id;  if (_openid_is_xri($claimed_id)) {    $xrds_url = 'http://xri.net/'. $claimed_id;  }  $url = @parse_url($xrds_url);  if ($url['scheme'] == 'http' || $url['scheme'] == 'https') {    // For regular URLs, try Yadis resolution first, then HTML-based discovery    $headers = array('Accept' => 'application/xrds+xml');    //TODO    $result = openid_http_request($xrds_url, $headers);    if (!isset($result->error)) {      if (isset($result->headers['Content-Type']) && preg_match("/application\/xrds\+xml/", $result->headers['Content-Type'])) {        // Parse XML document to find URL        $services = xrds_parse($result->data);      }      else {        $xrds_url = NULL;        if (isset($result->headers['X-XRDS-Location'])) {          $xrds_url = $result->headers['X-XRDS-Location'];        }        else {          // Look for meta http-equiv link in HTML head          $xrds_url = _openid_meta_httpequiv('X-XRDS-Location', $result->data);        }        if (!empty($xrds_url)) {          $headers = array('Accept' => 'application/xrds+xml');          //TODO          $xrds_result = openid_http_request($xrds_url, $headers);          if (!isset($xrds_result->error)) {            $services = xrds_parse($xrds_result->data);          }        }      }      // Check for HTML delegation      if (count($services) == 0) {        // Look for 2.0 links        $uri = _openid_link_href('openid2.provider', $result->data);        $delegate = _openid_link_href('openid2.local_id', $result->data);        $version = 2;        // 1.0 links        if (empty($uri)) {          $uri = _openid_link_href('openid.server', $result->data);          $delegate = _openid_link_href('openid.delegate', $result->data);          $version = 1;        }        if (!empty($uri)) {          $services[] = array('uri' => $uri, 'delegate' => $delegate, 'version' => $version);        }      }    }  }  return $services;}/** * Attempt to create a shared secret with the OpenID Provider. * * @param $op_endpoint URL of the OpenID Provider endpoint. * * @return $assoc_handle The association handle. */function openid_association($op_endpoint) {  // Remove Old Associations:  //TODO  $openid_association = Database::get_main_table(TABLE_MAIN_OPENID_ASSOCIATION);  api_sql_query("DELETE FROM $openid_association WHERE created + expires_in < %d", time());  // Check to see if we have an association for this IdP already  $assoc_handle = api_sql_query("SELECT assoc_handle FROM $openid_association WHERE idp_endpoint_uri = '%s'", $op_endpoint);  if (Database::num_rows($assoc_handle)<=1) {    $mod = OPENID_DH_DEFAULT_MOD;    $gen = OPENID_DH_DEFAULT_GEN;    $r = _openid_dh_rand($mod);    $private = bcadd($r, 1);    $public = bcpowmod($gen, $private, $mod);    // If there is no existing association, then request one    $assoc_request = openid_association_request($public);    $assoc_message = _openid_encode_message(_openid_create_message($assoc_request));    $assoc_headers = array('Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8');    //TODO    $assoc_result = openid_http_request($op_endpoint, $assoc_headers, 'POST', $assoc_message);    if (isset($assoc_result->error)) {      return FALSE;    }    $assoc_response = _openid_parse_message($assoc_result->data);    if (isset($assoc_response['mode']) && $assoc_response['mode'] == 'error') {        return FALSE;    }    if ($assoc_response['session_type'] == 'DH-SHA1') {      $spub = _openid_dh_base64_to_long($assoc_response['dh_server_public']);      $enc_mac_key = base64_decode($assoc_response['enc_mac_key']);      $shared = bcpowmod($spub, $private, $mod);      $assoc_response['mac_key'] = base64_encode(_openid_dh_xorsecret($shared, $enc_mac_key));    }    //TODO   	$openid_association = Database::get_main_table(TABLE_MAIN_OPENID_ASSOCIATION);    api_sql_query(sprintf("INSERT INTO $openid_association (idp_endpoint_uri, session_type, assoc_handle, assoc_type, expires_in, mac_key, created) VALUES('%s', '%s', '%s', '%s', %d, '%s', %d)",             $op_endpoint, $assoc_response['session_type'], $assoc_response['assoc_handle'], $assoc_response['assoc_type'], $assoc_response['expires_in'], $assoc_response['mac_key'], time()));    $assoc_handle = $assoc_response['assoc_handle'];  }  return $assoc_handle;}/** * ?

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -