29 require_once
'Auth/Container.php';
33 require_once
'DB.php';
89 $this->options[
'table'] =
'auth';
90 $this->options[
'usernamecol'] =
'username';
91 $this->options[
'passwordcol'] =
'password';
92 $this->options[
'dsn'] =
'';
93 $this->options[
'db_fields'] =
'';
94 $this->options[
'cryptType'] =
'md5';
95 $this->options[
'db_options'] = array();
96 $this->options[
'db_where'] =
'';
97 $this->options[
'auto_quote'] =
true;
101 if (empty($this->options[
'dsn'])) {
105 $this->options[
'dsn'] =
$dsn;
122 if (is_string(
$dsn) || is_array(
$dsn)) {
123 $this->db =& DB::connect(
$dsn, $this->options[
'db_options']);
124 }
elseif (is_subclass_of(
$dsn,
"db_common")) {
151 if (!DB::isConnection($this->db)) {
157 if ($this->options[
'auto_quote'] && $this->db->dsn[
'phptype'] !=
'sqlite') {
158 if (strpos(
'.', $this->options[
'table']) ===
false) {
159 $this->options[
'final_table'] = $this->db->quoteIdentifier($this->options[
'table']);
161 $t = explode(
'.', $this->options[
'table']);
162 for ($i = 0, $count = count(
$t); $i < $count; $i++)
163 $t[$i] = $this->db->quoteIdentifier(
$t[$i]);
164 $this->options[
'final_table'] = implode(
'.',
$t);
166 $this->options[
'final_usernamecol'] = $this->db->quoteIdentifier($this->options[
'usernamecol']);
167 $this->options[
'final_passwordcol'] = $this->db->quoteIdentifier($this->options[
'passwordcol']);
169 $this->options[
'final_table'] = $this->options[
'table'];
170 $this->options[
'final_usernamecol'] = $this->options[
'usernamecol'];
171 $this->options[
'final_passwordcol'] = $this->options[
'passwordcol'];
187 foreach ($array as
$key => $value) {
188 if (isset($this->options[
$key])) {
189 $this->options[
$key] = $value;
206 if (isset($this->options[
'db_fields'])) {
207 if (is_array($this->options[
'db_fields'])) {
208 if ($this->options[
'auto_quote']) {
210 foreach ($this->options[
'db_fields'] as $field) {
211 $fields[] = $this->db->quoteIdentifier($field);
213 return implode(
', ', $fields);
215 return implode(
', ', $this->options[
'db_fields']);
218 if (strlen($this->options[
'db_fields']) > 0) {
219 if ($this->options[
'auto_quote']) {
220 return $this->db->quoteIdentifier($this->options[
'db_fields']);
222 $this->options[
'db_fields'];
257 if (is_string($this->options[
'db_fields'])
258 && strstr($this->options[
'db_fields'],
'*')) {
261 $sql_from = $this->options[
'final_usernamecol'].
262 ", ".$this->options[
'final_passwordcol'];
265 $sql_from .=
', '.$fields;
269 $query =
"SELECT ".$sql_from.
270 " FROM ".$this->options[
'final_table'].
271 " WHERE ".$this->options[
'final_usernamecol'].
" = ".$this->db->quoteSmart($username);
274 if ($this->options[
'db_where'] !=
'') {
276 $query .=
" AND ".$this->options[
'db_where'];
283 if (DB::isError(
$res)) {
286 if (!is_array(
$res)) {
287 $this->activeUser =
'';
291 trim(
$res[$this->options[
'passwordcol']],
"\r\n"),
292 $this->options[
'cryptType'])) {
295 if (
$key == $this->options[
'passwordcol'] ||
296 $key == $this->options[
'usernamecol']) {
304 if (is_object($this->_auth_obj)) {
305 $this->_auth_obj->setAuthData(
$key, $value);
310 $this->activeUser =
$res[$this->options[
'usernamecol']];
313 $this->activeUser =
$res[$this->options[
'usernamecol']];