15 require_once
'Auth/Container.php';
16 require_once
'adodb.inc.php';
17 require_once
'adodb-pear.inc.php';
18 require_once
'adodb-errorpear.inc.php';
71 if (empty($this->options[
'dsn'])) {
72 PEAR::raiseError(
'No connection parameters specified!');
76 $this->options[
'dsn'] =
$dsn;
92 if (is_string($dsn) || is_array($dsn)) {
94 $this->db = ADONewConnection($dsn);
95 if( $err = ADODB_Pear_error() ) {
96 return PEAR::raiseError($err);
101 return PEAR::raiseError(
'The given dsn was not valid in file ' . __FILE__ .
' at line ' . __LINE__,
110 return PEAR::raiseError(ADODB_Pear_error());
131 $res = $this->
_connect($this->options[
'dsn']);
157 return $this->db->query($query);
171 $this->options[
'db_type'] =
'mysql';
172 $this->options[
'table'] =
'auth';
173 $this->options[
'usernamecol'] =
'username';
174 $this->options[
'passwordcol'] =
'password';
175 $this->options[
'dsn'] =
'';
176 $this->options[
'db_fields'] =
'';
177 $this->options[
'cryptType'] =
'md5';
191 foreach ($array as $key => $value) {
192 if (isset($this->options[$key])) {
193 $this->options[$key] = $value;
198 if(!empty($this->options[
'db_fields'])){
199 if(is_array($this->options[
'db_fields'])){
200 $this->options[
'db_fields'] = join($this->options[
'db_fields'],
', ');
202 $this->options[
'db_fields'] =
', '.$this->options[
'db_fields'];
227 return PEAR::raiseError($err->getMessage(), $err->getCode());
231 if(strstr($this->options[
'db_fields'],
'*')){
235 $sql_from = $this->options[
'usernamecol'] .
", ".$this->options[
'passwordcol'].$this->options[
'db_fields'];
238 $query =
"SELECT ".$sql_from.
239 " FROM ".$this->options[
'table'].
240 " WHERE ".$this->options[
'usernamecol'].
" = " . $this->db->Quote($username);
242 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
243 $rset = $this->db->Execute( $query );
244 $res = $rset->fetchRow();
247 return PEAR::raiseError($res->getMessage(), $res->getCode());
249 if (!is_array($res)) {
250 $this->activeUser =
'';
253 if ($this->verifyPassword(trim($password,
"\r\n"),
254 trim($res[$this->options[
'passwordcol']],
"\r\n"),
255 $this->options[
'cryptType'])) {
257 foreach ($res as $key => $value) {
258 if ($key == $this->options[
'passwordcol'] ||
259 $key == $this->options[
'usernamecol']) {
264 if(is_object($this->_auth_obj)){
265 $this->_auth_obj->setAuthData($key, $value);
267 Auth::setAuthData($key, $value);
274 $this->activeUser = $res[$this->options[
'usernamecol']];
285 return PEAR::raiseError($err->getMessage(), $err->getCode());
291 if(strstr($this->options[
'db_fields'],
'*')){
295 $sql_from = $this->options[
'usernamecol'] .
", ".$this->options[
'passwordcol'].$this->options[
'db_fields'];
298 $query = sprintf(
"SELECT %s FROM %s",
300 $this->options[
'table']
302 $res = $this->db->getAll($query, null, DB_FETCHMODE_ASSOC);
305 return PEAR::raiseError($res->getMessage(), $res->getCode());
307 foreach ($res as $user) {
308 $user[
'username'] = $user[$this->options[
'usernamecol']];
328 function addUser($username, $password, $additional =
"")
330 if (function_exists($this->options[
'cryptType'])) {
331 $cryptFunction = $this->options[
'cryptType'];
333 $cryptFunction =
'md5';
336 $additional_key =
'';
337 $additional_value =
'';
339 if (is_array($additional)) {
340 foreach ($additional as $key => $value) {
341 $additional_key .=
', ' . $key;
342 $additional_value .=
", '" . $value .
"'";
346 $query = sprintf(
"INSERT INTO %s (%s, %s%s) VALUES ('%s', '%s'%s)",
347 $this->options[
'table'],
348 $this->options[
'usernamecol'],
349 $this->options[
'passwordcol'],
352 $cryptFunction($password),
356 $res = $this->
query($query);
359 return PEAR::raiseError($res->getMessage(), $res->getCode());
378 $query = sprintf(
"DELETE FROM %s WHERE %s = '%s'",
379 $this->options[
'table'],
380 $this->options[
'usernamecol'],
384 $res = $this->
query($query);
387 return PEAR::raiseError($res->getMessage(), $res->getCode());
400 function dump( $var, $str, $vardump =
false ) {
401 print
"<H4>$str</H4><pre>";
402 ( !$vardump ) ? ( print_r( $var )) : ( var_dump( $var ));
addUser($username, $password, $additional="")
fetchData($username, $password)
dump( $var, $str, $vardump=false)
Auth_Container_ADOdb($dsn)