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.1 and 1.2

version 1.1, 2002/03/31 20:56:31 version 1.2, 2002/04/02 22:43:35
Line 56  class AuthDB
Line 56  class AuthDB
         /* PEAR Auth class compatibility */          /* PEAR Auth class compatibility */
         function getAuth()          function getAuth()
         {          {
                 return ($this->getStatus() == AUTH_DB_LOGGED_IN);                  return $this->getStatus() == AUTH_DB_LOGGED_IN;
         }          }
   
   
Line 98  class AuthDB
Line 98  class AuthDB
   
                 if (! empty($this->_username)) {                  if (! empty($this->_username)) {
   
                         $user_row = $this->_dbGetUserInfo($this->_username);                          $password = $this->_dbGetPassword();
                         if (is_array($user_row)                          if (isset($password) && ! strcmp($password, md5($this->_password)))
                                         && ! strcmp($user_row['password'], md5($this->_password))  
                            )  
                                 $status = AUTH_DB_LOGGED_IN;                                  $status = AUTH_DB_LOGGED_IN;
                         else                          else
                                 $status = AUTH_DB_FAILED;                                  $status = AUTH_DB_FAILED;
Line 114  class AuthDB
Line 112  class AuthDB
   
         function logout()          function logout()
         {          {
                 //if ($this->getAuth()) {                  if ($this->getAuth()) {
                 $this->_dbLogout();                          $this->_dbLogout();
                 $this->_status = AUTH_DB_LOGGED_OUT;                          $this->_status = AUTH_DB_LOGGED_OUT;
                 //}                  }
         }          }
   
         function getUsername()          function getUsername()
Line 127  class AuthDB
Line 125  class AuthDB
   
         function getUserInfo()          function getUserInfo()
         {          {
                 if ($this->getAuth())                  if ($this->getAuth()) {
                         return $this->_dbGetUserInfo($this->getUsername());                          $this->_username = $this->getUsername();
                           return $this->_dbGetUserInfo();
                   }
   
                 return false;                  return false;
         }          }
   
   
   
         // PRIVATE          // PRIVATE
   
         function _checkDB()          function _checkDB()
Line 152  class AuthDB
Line 151  class AuthDB
   
         function _error($error)          function _error($error)
         {          {
                 echo "AuthDB error: " . $error->getMessage() . "<br>";                  echo "AuthDB error: "
                           . $error->getMessage() . "<br>"
                           . $error->getDebugInfo() . "<br>";
                 die();                  die();
         }          }
   
Line 188  class AuthDB
Line 189  class AuthDB
                 return $ret;                  return $ret;
         }          }
   
           function _dbGetPassword()
           {
                   $query = sprintf('SELECT %s FROM %s WHERE %s = %s',
                                   $this->_options['users']['cols']['password'],
                                   $this->_options['users']['table'],
                                   $this->_options['users']['cols']['username'],
                                   $this->_db->quote($this->_username));
   
                   if (DB::isError($password = $this->_db->getOne($query)))
                           $this->_error($password);
   
                   return $password;
           }
   
         function _dbInsert()          function _dbInsert()
         {          {
                 mt_srand((double) microtime() * 1000000);                  mt_srand((double) microtime() * 1000000);
Line 351  class AuthDB
Line 366  class AuthDB
                 return $res[0];                  return $res[0];
         }          }
   
         function _dbGetUserInfo($username)          function _dbGetUserInfo()
         {          {
                 $query = sprintf('SELECT'                  $select_cols = array();
                                 .' users.id AS id,'                  $select_tables = array();
                                 .' users.username AS username,'                  $select_where = array();
                                 .' users.password AS password,'  
                                 .' users.member_id AS member_id,'                  foreach (array('sessions', 'users', 'groups') as $key) {
                                 .' roles.id AS role_id,'                          $prefix = $this->_options[$key]['prefix'];
                                 .' roles.name AS role_name,'                          $table = $this->_options[$key]['table'];
                                 .' roles.login AS role_login,'                          $cols = $this->_options[$key]['info_cols'];
                                 .' roles.members AS role_members,'  
                                 .' roles.clubs AS role_clubs,'                          if (! is_array($cols) || ! isset($table))
                                 .' roles.persons AS role_persons,'                                  continue;
                                 .' roles.organizations AS role_organizations,'  
                                 .' roles.sessions AS role_sessions,'                          if (in_array('*', $cols) == true) {
                                 .' roles.users AS role_users,'                                  if (DB::isError($info = $this->_db->tableInfo($table)))
                                 .' roles.roles AS role_roles'                                          $this->_error($info);
                                 .' FROM %s AS users, %s AS roles'  
                                 .' WHERE users.role_id = roles.id'                                  $cols = array();
                                 .' AND users.username = %s',                                  foreach ($info as $info_val)
                                 $this->_options['users']['table'],                                          $cols[] = $info_val['name'];
                                 $this->_options['groups']['table'],                          }
                                 $this->_db->quote($username));  
   
                                 //echo "<hr>$query</hr>";                          $select_tables[] = $table;
   
                 if (DB::isError($res = $this->_db->getRow($query)))                          foreach ($cols as $col_val)
                         $this->_error($res);                                  $select_cols[] = "$table.$col_val AS $prefix"."$col_val";
                   }
   
                 if (! isset($res))                  if (count($select_tables) == 0 || count($select_cols) == 0)
                         return array('username' => $username);                          return false;
   
                 //var_dump($res);                  if (is_array($this->_options['users']['info_cols'])
                                   && is_array($this->_options['groups']['info_cols'])) {
                           $select_where[] = sprintf('%s.%s = %s.%s',
                                           $this->_options['users']['table'],
                                           $this->_options['users']['cols']['group_id'],
                                           $this->_options['groups']['table'],
                                           $this->_options['groups']['cols']['id']);
                   }
   
                 return $res;                  if (is_array($this->_options['users']['info_cols'])
         }                                  && is_array($this->_options['sessions']['info_cols'])) {
                           $select_where[] = sprintf('%s.username = %s.%s',
                                           $this->_options['sessions']['table'],
                                           $this->_options['users']['table'],
                                           $this->_options['users']['cols']['username']);
                   }
   
                   if (is_array($this->_options['users']['info_cols'])) {
                           $select_where[] = sprintf('%s.username = %s',
                                           $this->_options['users']['table'],
                                           $this->_db->quote($this->_username));
                   }
   
                   if (is_array($this->_options['sessions']['info_cols'])) {
                           $select_where[] = sprintf('%s.session_id = %s',
                                           $this->_options['sessions']['table'],
                                           $this->_db->quote($this->_getProperty('session_id')));
                   }
   
                   $query = sprintf('SELECT %s FROM %s',
                           join(', ', $select_cols),
                           join(', ', $select_tables));
   
                   if (count($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)))
                           $this->_error($res);
   
                   return $res;
           }
   
 }  }
   

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

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