29 require_once
'Auth/Container.php';
33 require_once
'MDB2.php';
92 if (empty($this->options[
'dsn'])) {
96 $this->options[
'dsn'] =
$dsn;
113 if (is_string(
$dsn) || is_array(
$dsn)) {
115 } elseif (is_subclass_of(
$dsn,
'MDB2_Driver_Common')) {
120 return PEAR::raiseError(
'The given dsn was not valid in file ' . __FILE__ .
' at line ' . __LINE__,
133 if ($this->options[
'auto_quote']) {
134 if (strpos(
'.', $this->options[
'table']) ===
false) {
135 $this->options[
'final_table'] = $this->db->quoteIdentifier($this->options[
'table'],
true);
137 $t = explode(
'.', $this->options[
'table']);
138 for ($i = 0, $count = count(
$t); $i < $count; $i++)
139 $t[$i] = $this->db->quoteIdentifier(
$t[$i],
true);
140 $this->options[
'final_table'] = implode(
'.',
$t);
142 $this->options[
'final_usernamecol'] = $this->db->quoteIdentifier($this->options[
'usernamecol'],
true);
143 $this->options[
'final_passwordcol'] = $this->db->quoteIdentifier($this->options[
'passwordcol'],
true);
145 $this->options[
'final_table'] = $this->options[
'table'];
146 $this->options[
'final_usernamecol'] = $this->options[
'usernamecol'];
147 $this->options[
'final_passwordcol'] = $this->options[
'passwordcol'];
167 if (is_subclass_of($this->db,
'MDB2_Driver_Common')) {
170 return $this->
_connect($this->options[
'dsn']);
195 return $this->db->exec(
$query);
209 $this->options[
'table'] =
'auth';
210 $this->options[
'usernamecol'] =
'username';
211 $this->options[
'passwordcol'] =
'password';
212 $this->options[
'dsn'] =
'';
213 $this->options[
'db_fields'] =
'';
214 $this->options[
'cryptType'] =
'md5';
215 $this->options[
'db_options'] = array();
216 $this->options[
'db_where'] =
'';
217 $this->options[
'auto_quote'] =
true;
231 foreach ($array as $key => $value) {
232 if (isset($this->options[$key])) {
233 $this->options[$key] = $value;
250 if (isset($this->options[
'db_fields'])) {
251 if (is_array($this->options[
'db_fields'])) {
252 if ($this->options[
'auto_quote']) {
254 foreach ($this->options[
'db_fields'] as $field) {
255 $fields[] = $this->db->quoteIdentifier($field,
true);
257 return implode(
', ', $fields);
259 return implode(
', ', $this->options[
'db_fields']);
262 if (strlen($this->options[
'db_fields']) > 0) {
263 if ($this->options[
'auto_quote']) {
264 return $this->db->quoteIdentifier($this->options[
'db_fields'],
true);
266 return $this->options[
'db_fields'];
294 function fetchData($username, $password, $isChallengeResponse=
false)
304 if (is_string($this->options[
'db_fields'])
305 && strstr($this->options[
'db_fields'],
'*')) {
308 $sql_from = $this->options[
'final_usernamecol'].
309 ", ".$this->options[
'final_passwordcol'];
312 $sql_from .=
', '.$fields;
315 $query = sprintf(
"SELECT %s FROM %s WHERE %s = %s",
317 $this->options[
'final_table'],
318 $this->options[
'final_usernamecol'],
319 $this->db->quote($username,
'text')
323 if ($this->options[
'db_where'] !=
'') {
325 $query .=
" AND ".$this->options[
'db_where'];
334 if (!is_array(
$res)) {
335 $this->activeUser =
'';
340 $password = trim($password,
"\r\n");
341 $res[$this->options[
'passwordcol']] = trim(
$res[$this->options[
'passwordcol']],
"\r\n");
343 if ($isChallengeResponse) {
344 $res[$this->options[
'passwordcol']] =
345 md5(
$res[$this->options[
'passwordcol']].$this->_auth_obj->session[
'loginchallenege']);
347 if ($this->options[
'cryptType'] ==
'md5') {
348 $res[$this->options[
'passwordcol']] = md5(
$res[$this->options[
'passwordcol']]);
352 $res[$this->options[
'passwordcol']],
353 $this->options[
'cryptType'])) {
355 foreach (
$res as $key => $value) {
356 if ($key == $this->options[
'passwordcol'] ||
357 $key == $this->options[
'usernamecol']) {
365 $this->_auth_obj->setAuthData($key, $value);
370 $this->activeUser =
$res[$this->options[
'usernamecol']];
394 if ( is_string($this->options[
'db_fields'])
395 && strstr($this->options[
'db_fields'],
'*')) {
398 $sql_from = $this->options[
'final_usernamecol'].
399 ", ".$this->options[
'final_passwordcol'];
402 $sql_from .=
', '.$fields;
406 $query = sprintf(
'SELECT %s FROM %s',
408 $this->options[
'final_table']
412 if ($this->options[
'db_where'] !=
'') {
414 $query .=
" WHERE ".$this->options[
'db_where'];
423 foreach (
$res as $user) {
424 $user[
'username'] = $user[$this->options[
'usernamecol']];
455 if (isset($this->options[
'cryptType']) && $this->options[
'cryptType'] ==
'none') {
456 $cryptFunction =
'strval';
457 } elseif (isset($this->options[
'cryptType']) && function_exists($this->options[
'cryptType'])) {
458 $cryptFunction = $this->options[
'cryptType'];
460 $cryptFunction =
'md5';
463 $password = $cryptFunction($password);
465 $additional_key =
'';
466 $additional_value =
'';
470 if ($this->options[
'auto_quote']) {
471 $additional_key .=
', ' . $this->db->quoteIdentifier($key,
true);
473 $additional_key .=
', ' . $key;
475 $additional_value .=
', ' . $this->db->quote($value,
'text');
479 $query = sprintf(
"INSERT INTO %s (%s, %s%s) VALUES (%s, %s%s)",
480 $this->options[
'final_table'],
481 $this->options[
'final_usernamecol'],
482 $this->options[
'final_passwordcol'],
484 $this->db->quote($username,
'text'),
485 $this->db->quote($password,
'text'),
519 $query = sprintf(
"DELETE FROM %s WHERE %s = %s",
520 $this->options[
'final_table'],
521 $this->options[
'final_usernamecol'],
522 $this->db->quote($username,
'text')
526 if ($this->options[
'db_where'] !=
'') {
528 $query .=
" AND ".$this->options[
'db_where'];
559 if (isset($this->options[
'cryptType']) && $this->options[
'cryptType'] ==
'none') {
560 $cryptFunction =
'strval';
561 } elseif (isset($this->options[
'cryptType']) && function_exists($this->options[
'cryptType'])) {
562 $cryptFunction = $this->options[
'cryptType'];
564 $cryptFunction =
'md5';
567 $password = $cryptFunction($password);
569 $query = sprintf(
"UPDATE %s SET %s = %s WHERE %s = %s",
570 $this->options[
'final_table'],
571 $this->options[
'final_passwordcol'],
572 $this->db->quote($password,
'text'),
573 $this->options[
'final_usernamecol'],
574 $this->db->quote($username,
'text')
578 if ($this->options[
'db_where'] !=
'') {
580 $query .=
" AND ".$this->options[
'db_where'];
605 return in_array($this->options[
'cryptType'], array(
'md5',
'none',
''));
618 return $this->options[
'cryptType'];