Source for file auth.inc.php
Documentation is available at auth.inc.php
* This file is part of the VCL for PHP project
* Copyright (c) 2004-2007 qadram software <support@qadram.com>
* Checkout AUTHORS file for more information on the developers
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library 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
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* A common base class for user authentication, inherit from it to create new
* types of authentication
//Calls inherited constructor
* Specifies whether the user is logged or not
function readLogged() { return $this->_logged; }
function writeLogged($value) { $this->_logged= $value; }
* Authenticate the user inside the system
* @param string $username Name of the user to authenticate
* @param string $password Password of the user to authenticate
* DatabaseUser can be used to authenticate an user against a database table
* Set DriverName, Host, User, Password, FieldName and TableName to allow the component
* find the information to authenticate
* Table that stores the user information
function getUsersTable() { return $this->_userstable; }
function setUsersTable($value) { $this->_userstable= $value; }
* Field name of the column that stores the user name
* Field name of the column that stores the password
* Type of database, it uses a Database component, so the value for this
* property is the same as the Database::DriverName property
function getDriverName() { return $this->_drivername; }
function setDriverName($value) { $this->_drivername= $value; }
function setDatabaseName($value) { $this->_databasename= $value; }
function getHost() { return $this->_host; }
function setHost($value) { $this->_host= $value; }
* User name to authentitcate
function getUser() { return $this->_user; }
function setUser($value) { $this->_user= $value; }
* Password to authenticate
function getPassword() { return $this->_password; }
function setPassword($value) { $this->_password= $value; }
* @param string $username Username to authenticate
* @param string $passwrod Password of the user
$db->DriverName= $this->DriverName;
$db->DatabaseName= $this->DatabaseName;
$db->Password= $this->Password;
$tb->Filter= " ". $this->UserNameFieldName. " = '". $username. "' ";
$tb->TableName= $this->UsersTable;
$fname= $this->UserNameFieldName;
$pname= $this->PasswordFieldName;
//check if the user&password combination exists
if (($tb->$fname== $username) && ($tb->$pname== $password))
* Performs authentication using basic HTTP
* This component is useful to easily protect web pages just by dropping a component.
* For basic usage, just set UserName and Password to the valid value to log in
* and call the Execute() method in the OnBeforeShow event of your page.
* For more advance usage, @see OnAuthenticate it allows you to authenticate using your
function getPassword() { return $this->_password; }
function setPassword($value) { $this->_password= $value; }
function defaultPassword() { return ""; }
function getUsername() { return $this->_username; }
function setUsername($value) { $this->_username= $value; }
function defaultUsername() { return ""; }
* Error message to show when the user is not authenticated
function setErrorMessage($value) { $this->_errormessage= $value; }
function defaultErrorMessage() { return "Unauthorized"; }
* Title of the authentication dialog to show the user
function getTitle() { return $this->_title; }
function setTitle($value) { $this->_title= $value; }
function defaultTitle() { return "Login"; }
* It's fired when the component needs to authenticate the user by code.
* In $params['username'] you will get the username entered by the user
* In $params['password'] you will get the password entered by the user
* Return true if the user should get authenticated, false otherwise
function defaultOnAuthenticate() { return ""; }
* Executes the authentication and checks if the user has been authenticated or not
* If the user is not authenticated, requests again the username/password
* If the event OnAuthenticate is assigned, valid username/password will be provided by code
* if not, properties Username/Password will be used to authenticate
//If not is set, requests for it
if(!isset ($_SERVER['PHP_AUTH_USER']))
header('WWW-Authenticate: Basic realm="' . $this->_title. '"');
header('HTTP/1.0 401 Unauthorized');
//If not it's the right combination, request for it
if ($this->OnAuthenticate!= null)
$result= $this->callEvent('onauthenticate', array('username'=> $_SERVER['PHP_AUTH_USER'],'password'=> $_SERVER['PHP_AUTH_PW']));
header('WWW-Authenticate: Basic realm="' . $this->_title. '"');
header('HTTP/1.0 401 Unauthorized');
if (($_SERVER['PHP_AUTH_USER'] != $this->_username) || ($_SERVER['PHP_AUTH_PW'] != $this->_password))
header('WWW-Authenticate: Basic realm="' . $this->_title. '"');
header('HTTP/1.0 401 Unauthorized');
|