Location: PHPKode > projects > phpBB login classes > phpbb-login-classes/class_loginphpBB.php
<?php
/****************************************************************
*****************************************************************
Copyright (C) 2003  Matthieu MARY http://www.phplibrairies.com

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

You can found more information about GPL licence at:
http://www.gnu.org/licenses/gpl.html

for contact me: http://www.phplibrairies.com
****************************************************************
****************************************************************/
/**
 * create the : january 25th 2004.
 * @author      Matthieu MARY
 * @version     %I%, %G%
 * @since       0.1.0
 */
require_once 'class_database.php';

class login extends database
{
	/**
	 * @shortdesc : name of the phpBB user table
	 * @private
	 * @type string
	 **/
	var $userTable;
	/**
	 * @shortdesc : name of the phpBB user table
	 * @private
	 * @type string
	 **/
	var $aErrors;
	/**
	 * @shortdesc : database object
	 * @private
	 * @type mixed
	 **/
	var $oDB;
	/**
	 * @shortdesc : builder
	 * builder
	 * @param string configFile : relative url to phpBB config File
	 * @param string constantFile : relative url to phpBB constant File
	 * @public
	 * @type void
	 **/
	function login($configFile,$constantFile)
	{
		if ((!is_file($configFile))||(strpos(basename($configFile),'config.')!=0)) return $this->_err_add('invalid config file ['.$configFile.']');
        if ((!is_file($constantFile))||(strpos(basename($constantFile),'constants.')!=0)) return $this->_err_add('invalid constants file ['.$configFile.']');
		require_once($configFile);
		// set a constant to excluse the hacking attempt error
		define('IN_PHPBB',true);
		require_once($constantFile);
		$this->userTable = USERS_TABLE;
		$db = array('type' => 'mysql',
     				'login' => $dbuser,
    				'mdp'=> $dbpasswd,
     				'server' => $dbhost,
     				'db'=> $dbname
			);
		$this->oDB = new database($db);
		if (count($this->oDB->aErr)>0)
		{
			$this->aErrors = $this->oDB->aErr;
			return false;
		}
	}

	/**
	 * @shortdesc : check if a user is valid
	 * check if a user is valid
	 * @param string login : login value
	 * @param string password : password
	 * @public
	 * @type mixed
	 **/
	function verify($login,$password)
	{
		$login = addslashes($login);
		$sql = 'SELECT user_id, username, user_password, user_active, user_level FROM ' .$this->userTable. ' WHERE username = \'' . $login . "'";
		$this->oDB->execute($sql);
		if ($this->oDB->aErr) return $this->_err_add('unable to get datas from user table');
		$bResult = false;
		if( $row = $this->oDB->oR->fetchRow(DB_FETCHMODE_ASSOC))
		{
			if( md5($password) == $row['user_password'] && $row['user_active']) $bResult = intval($row['user_id']);
		}
	    return $bResult;
	}


	function _err_add($err)
	{
		$this->aErrors[] = $err;
		return false;
	}
}
?>
Return current item: phpBB login classes