Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Wednesday, October 14, 2026

Diff for phpPlatonLib/Auth_AuthDB/AuthDB.php between version 1.5 and 1.6

version 1.5, 2002/05/15 00:56:20 version 1.6, 2002/05/29 15:08:32
Line 25 
Line 25 
  *   *
  * 31/3/2002 - initial release   * 31/3/2002 - initial release
  * 13/5/2002 - headers update   * 13/5/2002 - headers update
    * 29/5/2002 - code cleanup, little improvements (username and password
    *             moved to props array)
  */   */
   
 require_once "DB.php";  require_once 'DB.php';
   
 define("AUTH_DB_UNDEFINED",              0);  define('AUTH_DB_COOKIE_NAME', 'AuthDB_session_id_cookie');
 define("AUTH_DB_NOT_LOGGED",    -1);  define('AUTH_DB_UNDEFINED',              0);
 define("AUTH_DB_LOGGED_IN",              1);  define('AUTH_DB_NOT_LOGGED',    -1);
 define("AUTH_DB_LOGGED_OUT",    -2);  define('AUTH_DB_LOGGED_IN',              1);
 define("AUTH_DB_EXPIRED",               -3);  define('AUTH_DB_LOGGED_OUT',    -2);
 define("AUTH_DB_TIMEOUT",               -4);  define('AUTH_DB_EXPIRED',               -3);
 define("AUTH_DB_FAILED",                -5);  define('AUTH_DB_TIMEOUT',               -4);
 //define("AUTH_DB_ERROR",                       -6);  define('AUTH_DB_FAILED',                -5);
   //define('AUTH_DB_ERROR',               -6);
   
   
 class AuthDB  class AuthDB
 {  {
         var $_status = AUTH_DB_UNDEFINED;          var $_status  = AUTH_DB_UNDEFINED;
   
         var $_options = null;          var $_options = null;
         var $_db = null;          var $_db      = null;
   
         var $_username = null;  
         var $_password = null;  
   
         var $_props = array(          var $_props = array(
                           'username'   => null,
                           'password'   => null,
                         'session_id' => null,                          'session_id' => null,
                         'user_agent' => null,                          'user_agent' => null,
                         'remote_ip' => null                          'remote_ip'  => null
                         );                          );
   
         function AuthDB($options)          function AuthDB($options)
Line 67  class AuthDB
Line 68  class AuthDB
                 /* Empty passwords are allowed. Empty usernames not. */                  /* Empty passwords are allowed. Empty usernames not. */
   
                 if (isset($HTTP_POST_VARS['username'])                  if (isset($HTTP_POST_VARS['username'])
                                 && $HTTP_POST_VARS['username'] != "") {                                  && $HTTP_POST_VARS['username'] != '') {
                         $this->_username = $HTTP_POST_VARS['username'];                          $this->_props['username'] = $HTTP_POST_VARS['username'];
                 }  
   
                 if (isset($HTTP_POST_VARS['password'])) {                          if (isset($HTTP_POST_VARS['password'])) {
                         $this->_password = $HTTP_POST_VARS['password'];                                  $this->_props['password'] = $HTTP_POST_VARS['password'];
                           }
                 }                  }
         }          }
   
Line 82  class AuthDB
Line 83  class AuthDB
                 return $this->getStatus() == AUTH_DB_LOGGED_IN;                  return $this->getStatus() == AUTH_DB_LOGGED_IN;
         }          }
   
   
         function getStatus()          function getStatus()
         {          {
                 if ($this->_status != AUTH_DB_UNDEFINED)                  if ($this->_status != AUTH_DB_UNDEFINED)
Line 119  class AuthDB
Line 119  class AuthDB
         {          {
                 $status = AUTH_DB_UNDEFINED;                  $status = AUTH_DB_UNDEFINED;
   
                 if (! empty($this->_username)) {                  if (! empty($this->_props['username'])) {
   
                         $password = $this->_dbGetPassword();                          $password = $this->_dbGetPassword();
                         if (isset($password) && ! strcmp($password, md5($this->_password)))                          if (isset($password)
                                   && ! strcmp($password, md5($this->_props['password']))) {
                                 $status = AUTH_DB_LOGGED_IN;                                  $status = AUTH_DB_LOGGED_IN;
                         else                          }
                           else {
                                 $status = AUTH_DB_FAILED;                                  $status = AUTH_DB_FAILED;
                           }
                 }                  }
                 else                  else {
                         $status = AUTH_DB_NOT_LOGGED;                          $status = AUTH_DB_NOT_LOGGED;
                   }
   
                 return $status;                  return $status;
         }          }
Line 149  class AuthDB
Line 153  class AuthDB
         function getUserInfo()          function getUserInfo()
         {          {
                 if ($this->getAuth()) {                  if ($this->getAuth()) {
                         $this->_username = $this->getUsername();                          $this->_props['username'] = $this->getUsername();
                         return $this->_dbGetUserInfo();                          return $this->_dbGetUserInfo();
                 }                  }
   
Line 157  class AuthDB
Line 161  class AuthDB
         }          }
   
   
         // PRIVATE          // Private methods
   
         function _checkDB()          function _checkDB()
         {          {
Line 190  class AuthDB
Line 194  class AuthDB
                                 global $HTTP_SERVER_VARS;                                  global $HTTP_SERVER_VARS;
                                 $ret = $HTTP_SERVER_VARS['HTTP_USER_AGENT'];                                  $ret = $HTTP_SERVER_VARS['HTTP_USER_AGENT'];
                                 $ret = substr(stripslashes($ret), 0, 255);                                  $ret = substr(stripslashes($ret), 0, 255);
                                 //echo "Returning User Agent: "  
                                 //      .htmlentities($ret)."<hr>";  
                                 break;                                  break;
   
                         case 'remote_ip':                          case 'remote_ip':
Line 205  class AuthDB
Line 207  class AuthDB
                         default:                          default:
                         case 'session_id':                          case 'session_id':
                                 global $HTTP_COOKIE_VARS;                                  global $HTTP_COOKIE_VARS;
                                 if (isset($HTTP_COOKIE_VARS['AuthDB_session_id_cookie'])) {                                  if (isset($HTTP_COOKIE_VARS[AUTH_DB_COOKIE_NAME])) {
                                         $ret = $HTTP_COOKIE_VARS['AuthDB_session_id_cookie'];                                          $ret = $HTTP_COOKIE_VARS[AUTH_DB_COOKIE_NAME];
                                         $ret = intval(stripslashes($ret));                                          $ret = intval(stripslashes($ret));
                                 }                                  }
                                 else {                                  else {
Line 225  class AuthDB
Line 227  class AuthDB
                                 $this->_options['users']['cols']['password'],                                  $this->_options['users']['cols']['password'],
                                 $this->_options['users']['table'],                                  $this->_options['users']['table'],
                                 $this->_options['users']['cols']['username'],                                  $this->_options['users']['cols']['username'],
                                 $this->_db->quote($this->_username));                                  $this->_db->quote($this->_props['username']));
   
                 if (DB::isError($password = $this->_db->getOne($query)))                  if (DB::isError($password = $this->_db->getOne($query)))
                         $this->_error($password);                          $this->_error($password);
Line 250  class AuthDB
Line 252  class AuthDB
   
                 } while (isset($res));                  } while (isset($res));
   
                 setcookie("AuthDB_session_id_cookie", $session_id, 0,                  setcookie(AUTH_DB_COOKIE_NAME, $session_id, 0, '', '', false);
                                 '' /* $Adores_URL . $Adores_ADMIN_DIRECTORY */,  
                                 '' /* domain */, false);  
   
                 $query = sprintf('INSERT INTO %s'                  $query = sprintf('INSERT INTO %s'
                                 .' (status, login, logout,'                                  .' (status, login, logout,'
Line 261  class AuthDB
Line 261  class AuthDB
                                 .' ("online", sysdate(), sysdate(),'                                  .' ("online", sysdate(), sysdate(),'
                                         .' %s, %s, %s, %s)',                                          .' %s, %s, %s, %s)',
                                 $this->_options['sessions']['table'],                                  $this->_options['sessions']['table'],
                                 $this->_db->quote($this->_username),                                  $this->_db->quote($this->_props['username']),
                                 $this->_db->quote($session_id),                                  $this->_db->quote($session_id),
                                 $this->_db->quote($this->_getProperty('remote_ip')),                                  $this->_db->quote($this->_getProperty('remote_ip')),
                                 $this->_db->quote($this->_getProperty('user_agent')));                                  $this->_db->quote($this->_getProperty('user_agent')));
Line 283  class AuthDB
Line 283  class AuthDB
                                 .' ("failed", sysdate(), sysdate(),'                                  .' ("failed", sysdate(), sysdate(),'
                                         .' %s, %s, %s, %s)',                                          .' %s, %s, %s, %s)',
                                 $this->_options['sessions']['table'],                                  $this->_options['sessions']['table'],
                                 $this->_db->quote($this->_username),                                  $this->_db->quote($this->_props['username']),
                                 $this->_db->quote($this->_password),                                  $this->_db->quote($this->_props['password']),
                                 $this->_db->quote($this->_getProperty('remote_ip')),                                  $this->_db->quote($this->_getProperty('remote_ip')),
                                 $this->_db->quote($this->_getProperty('user_agent')));                                  $this->_db->quote($this->_getProperty('user_agent')));
   
Line 330  class AuthDB
Line 330  class AuthDB
                 if (DB::isError($res = $this->_db->query($query)))                  if (DB::isError($res = $this->_db->query($query)))
                         $this->_error($res);                          $this->_error($res);
   
                 setcookie("AuthDB_session_id_cookie");                  setcookie(AUTH_DB_COOKIE_NAME);
   
                 return true;                  return true;
         }          }
Line 448  class AuthDB
Line 448  class AuthDB
                 if (is_array($this->_options['users']['info_cols'])) {                  if (is_array($this->_options['users']['info_cols'])) {
                         $select_where[] = sprintf('%s.username = %s',                          $select_where[] = sprintf('%s.username = %s',
                                         $this->_options['users']['table'],                                          $this->_options['users']['table'],
                                         $this->_db->quote($this->_username));                                          $this->_db->quote($this->_props['username']));
                 }                  }
   
                 if (is_array($this->_options['sessions']['info_cols'])) {                  if (is_array($this->_options['sessions']['info_cols'])) {
Line 458  class AuthDB
Line 458  class AuthDB
                 }                  }
   
                 $query = sprintf('SELECT %s FROM %s',                  $query = sprintf('SELECT %s FROM %s',
                         join(', ', $select_cols),                                  join(', ', $select_cols),
                         join(', ', $select_tables));                                  join(', ', $select_tables));
   
                 if (count($select_where))                  if (count($select_where))
                         $query .= ' WHERE ' . join(' AND ', $select_where);                          $query .= ' WHERE ' . join(' AND ', $select_where);
   
                 //echo "$query<hr>";  
 /*  
                 $query = sprintf('SELECT'  
                                 .' %s.*, %s.*, %s.*'  
                                 .' FROM %s, %s, %s'  
                                 .' WHERE %s.%s = %s.%s'  
                                 .' AND %s.username = %s.%s'  
                                 .' AND %s.username = %s'  
                                 .' AND %s.session_id = %s',  
                                 $tbl_users, $tbl_groups, $tbl_sessions,  
                                 $tbl_users, $tbl_groups, $tbl_sessions,  
                                 $tbl_users, $this->_options['users']['cols']['group_id'],  
                                 $tbl_groups, $this->_options['groups']['cols']['id'],  
                                 $tbl_sessions, $tbl_users, $this->_options['users']['cols']['username'],  
                                 $tbl_sessions, $this->_db->quote($username),  
                                 $tbl_sessions, $this->_db->quote($this->_getProperty('session_id'))  
                                 );  
 */  
                 if (DB::isError($res = $this->_db->getRow($query)))                  if (DB::isError($res = $this->_db->getRow($query)))
                         $this->_error($res);                          $this->_error($res);
   

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top