28 require_once 
'Auth/Container.php';
 
   32 require_once 
'DB.php';
 
   92             if (empty($this->options[
'dsn'])) {
 
   96             $this->options[
'dsn'] = 
$dsn;
 
  114         if (is_string(
$dsn) || is_array(
$dsn)) {
 
  115             $this->db = DB::Connect(
$dsn, $this->options[
'db_options']);
 
  116         } elseif (is_subclass_of(
$dsn, 
'db_common')) {
 
  118         } elseif (DB::isError(
$dsn)) {
 
  121             return PEAR::raiseError(
'The given dsn was not valid in file ' . __FILE__ . 
' at line ' . __LINE__,
 
  150         if (!DB::isConnection($this->db)) {
 
  156         if ($this->options[
'auto_quote'] && $this->db->dsn[
'phptype'] != 
'sqlite') {
 
  157             if (strpos(
'.', $this->options[
'table']) === 
false) {
 
  158                 $this->options[
'final_table'] = $this->db->quoteIdentifier($this->options[
'table']);
 
  160                 $t = explode(
'.', $this->options[
'table']);
 
  161                 for ($i = 0, $count = count(
$t); $i < $count; $i++)
 
  162                     $t[$i] = $this->db->quoteIdentifier(
$t[$i]);
 
  163                 $this->options[
'final_table'] = implode(
'.', 
$t);
 
  165             $this->options[
'final_usernamecol'] = $this->db->quoteIdentifier($this->options[
'usernamecol']);
 
  166             $this->options[
'final_passwordcol'] = $this->db->quoteIdentifier($this->options[
'passwordcol']);
 
  168             $this->options[
'final_table'] = $this->options[
'table'];
 
  169             $this->options[
'final_usernamecol'] = $this->options[
'usernamecol'];
 
  170             $this->options[
'final_passwordcol'] = $this->options[
'passwordcol'];
 
  196         return $this->db->query(
$query);
 
  210         $this->options[
'table']       = 
'auth';
 
  211         $this->options[
'usernamecol'] = 
'username';
 
  212         $this->options[
'passwordcol'] = 
'password';
 
  213         $this->options[
'dsn']         = 
'';
 
  214         $this->options[
'db_fields']   = 
'';
 
  215         $this->options[
'cryptType']   = 
'md5';
 
  216         $this->options[
'db_options']  = array();
 
  217         $this->options[
'db_where']    = 
'';
 
  218         $this->options[
'auto_quote']  = 
true;
 
  232         foreach ($array as $key => $value) {
 
  233             if (isset($this->options[$key])) {
 
  234                 $this->options[$key] = $value;
 
  251         if (isset($this->options[
'db_fields'])) {
 
  252             if (is_array($this->options[
'db_fields'])) {
 
  253                 if ($this->options[
'auto_quote']) {
 
  255                     foreach ($this->options[
'db_fields'] as $field) {
 
  256                         $fields[] = $this->db->quoteIdentifier($field);
 
  258                     return implode(
', ', $fields);
 
  260                     return implode(
', ', $this->options[
'db_fields']);
 
  263                 if (strlen($this->options[
'db_fields']) > 0) {
 
  264                     if ($this->options[
'auto_quote']) {
 
  265                         return $this->db->quoteIdentifier($this->options[
'db_fields']);
 
  267                         return $this->options[
'db_fields'];
 
  295     function fetchData($username, $password, $isChallengeResponse=
false)
 
  305         if (is_string($this->options[
'db_fields'])
 
  306             && strstr($this->options[
'db_fields'], 
'*')) {
 
  309             $sql_from = $this->options[
'final_usernamecol'].
 
  310                 ", ".$this->options[
'final_passwordcol'];
 
  313                 $sql_from .= 
', '.$fields;
 
  317         $query = 
"SELECT ".$sql_from.
 
  318                 " FROM ".$this->options[
'final_table'].
 
  319                 " WHERE ".$this->options[
'final_usernamecol'].
" = ".$this->db->quoteSmart($username);
 
  322         if ($this->options[
'db_where'] != 
'') {
 
  324             $query .= 
" AND ".$this->options[
'db_where'];
 
  331         if (DB::isError(
$res)) {
 
  335         if (!is_array(
$res)) {
 
  336             $this->activeUser = 
'';
 
  341         $password = trim($password, 
"\r\n");
 
  342         $res[$this->options[
'passwordcol']] = trim(
$res[$this->options[
'passwordcol']], 
"\r\n");
 
  345         if ($isChallengeResponse) {
 
  346             $res[$this->options[
'passwordcol']] = md5(
$res[$this->options[
'passwordcol']]
 
  347                     .$this->_auth_obj->session[
'loginchallenege']);
 
  350             if ($this->options[
'cryptType'] == 
'md5') {
 
  351                 $res[$this->options[
'passwordcol']] = md5(
$res[$this->options[
'passwordcol']]);
 
  358                                   $res[$this->options[
'passwordcol']],
 
  359                                   $this->options[
'cryptType'])) {
 
  361             foreach (
$res as $key => $value) {
 
  362                 if ($key == $this->options[
'passwordcol'] ||
 
  363                     $key == $this->options[
'usernamecol']) {
 
  372                 $this->_auth_obj->setAuthData($key, $value);
 
  376         $this->activeUser = 
$res[$this->options[
'usernamecol']];
 
  400         if (   is_string($this->options[
'db_fields'])
 
  401             && strstr($this->options[
'db_fields'], 
'*')) {
 
  404             $sql_from = $this->options[
'final_usernamecol'].
 
  405                 ", ".$this->options[
'final_passwordcol'];
 
  408                 $sql_from .= 
', '.$fields;
 
  412         $query = sprintf(
"SELECT %s FROM %s",
 
  414                          $this->options[
'final_table']
 
  418         if ($this->options[
'db_where'] != 
'') {
 
  420             $query .= 
" WHERE ".$this->options[
'db_where'];
 
  427         if (DB::isError(
$res)) {
 
  431                 $user[
'username'] = $user[$this->options[
'usernamecol']];
 
  460         if (   isset($this->options[
'cryptType'])
 
  461             && $this->options[
'cryptType'] == 
'none') {
 
  462             $cryptFunction = 
'strval';
 
  463         } elseif (   isset($this->options[
'cryptType'])
 
  464                   && function_exists($this->options[
'cryptType'])) {
 
  465             $cryptFunction = $this->options[
'cryptType'];
 
  467             $cryptFunction = 
'md5';
 
  470         $password = $cryptFunction($password);
 
  472         $additional_key   = 
'';
 
  473         $additional_value = 
'';
 
  477                 if ($this->options[
'auto_quote']) {
 
  478                     $additional_key .= 
', ' . $this->db->quoteIdentifier($key);
 
  480                     $additional_key .= 
', ' . $key;
 
  482                 $additional_value .= 
", " . $this->db->quoteSmart($value);
 
  486         $query = sprintf(
"INSERT INTO %s (%s, %s%s) VALUES (%s, %s%s)",
 
  487                          $this->options[
'final_table'],
 
  488                          $this->options[
'final_usernamecol'],
 
  489                          $this->options[
'final_passwordcol'],
 
  491                          $this->db->quoteSmart($username),
 
  492                          $this->db->quoteSmart($password),
 
  500         if (DB::isError(
$res)) {
 
  528         if ($this->options[
'db_where'] != 
'') {
 
  530             $where = 
" AND ".$this->options[
'db_where'];
 
  535         $query = sprintf(
"DELETE FROM %s WHERE %s = %s %s",
 
  536                          $this->options[
'final_table'],
 
  537                          $this->options[
'final_usernamecol'],
 
  538                          $this->db->quoteSmart($username),
 
  546         if (DB::isError(
$res)) {
 
  570         if (   isset($this->options[
'cryptType'])
 
  571             && $this->options[
'cryptType'] == 
'none') {
 
  572             $cryptFunction = 
'strval';
 
  573         } elseif (   isset($this->options[
'cryptType'])
 
  574                   && function_exists($this->options[
'cryptType'])) {
 
  575             $cryptFunction = $this->options[
'cryptType'];
 
  577             $cryptFunction = 
'md5';
 
  580         $password = $cryptFunction($password);
 
  583         if ($this->options[
'db_where'] != 
'') {
 
  585             $where = 
" AND ".$this->options[
'db_where'];
 
  590         $query = sprintf(
"UPDATE %s SET %s = %s WHERE %s = %s %s",
 
  591                          $this->options[
'final_table'],
 
  592                          $this->options[
'final_passwordcol'],
 
  593                          $this->db->quoteSmart($password),
 
  594                          $this->options[
'final_usernamecol'],
 
  595                          $this->db->quoteSmart($username),
 
  603         if (DB::isError(
$res)) {
 
  622         return in_array($this->options[
'cryptType'], array(
'md5', 
'none', 
''));
 
  633         return($this->options[
'cryptType']);