2000-05-10 22:38:21 +00:00
|
|
|
<?
|
|
|
|
/*
|
|
|
|
auth.php
|
|
|
|
|
|
|
|
Authentication/Authorization function library
|
|
|
|
|
2001-07-19 11:52:47 +00:00
|
|
|
Copyright (C) 2000, 2001 Jeff Teunissen <deek@quakeforge.net>
|
2000-05-10 22:38:21 +00:00
|
|
|
|
|
|
|
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 (at your option) 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:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
have ('auth');
|
2000-06-18 23:52:50 +00:00
|
|
|
need ('table');
|
2002-02-22 07:22:34 +00:00
|
|
|
|
|
|
|
if (!defined ('_SQLCONSTS_')) {
|
|
|
|
define ('_SQLCONSTS_', 1);
|
|
|
|
require siteHome . '/../etc/sql.conf';
|
|
|
|
}
|
|
|
|
|
2000-05-10 22:38:21 +00:00
|
|
|
/* SQL definition for member list table
|
|
|
|
CREATE TABLE members (
|
|
|
|
u_key int DEFAULT '0' NOT NULL auto_increment PRIMARY KEY,
|
|
|
|
u_admin char DEFAULT 'N' NOT NULL,
|
|
|
|
u_username tinytext DEFAULT '' NOT NULL,
|
|
|
|
u_password tinytext DEFAULT '' NOT NULL,
|
|
|
|
u_fullname tinytext DEFAULT '' NOT NULL,
|
|
|
|
u_email tinytext DEFAULT '' NOT NULL,
|
|
|
|
u_phone tinytext DEFAULT '',
|
|
|
|
u_addr1 tinytext DEFAULT '',
|
|
|
|
u_addr2 tinytext DEFAULT '',
|
|
|
|
u_country tinytext DEFAULT '',
|
|
|
|
u_secret tinytext,
|
|
|
|
u_plan text DEFAULT ''
|
|
|
|
);
|
|
|
|
*/
|
|
|
|
|
|
|
|
define ('EXPIRY', 86400); // Seconds until cookie expires
|
|
|
|
|
|
|
|
define ('thisUrl', ereg_replace ('index.php', '', getenv ('SCRIPT_NAME')));
|
|
|
|
|
|
|
|
/*
|
|
|
|
authCreateSecret
|
|
|
|
|
|
|
|
Generate a secret key for user's session
|
|
|
|
*/
|
2000-06-18 23:52:50 +00:00
|
|
|
function authCreateSecret ($userName, $encryptedPassWord)
|
2000-05-10 22:38:21 +00:00
|
|
|
{
|
2000-06-18 23:52:50 +00:00
|
|
|
$digest = md5 (time ());
|
2000-05-10 22:38:21 +00:00
|
|
|
$cookie = "$userName-$encryptedPassWord-$digest";
|
2001-07-19 11:52:47 +00:00
|
|
|
SetCookie ("loginInfo", $cookie, (time () + EXPIRY));
|
2000-05-10 22:38:21 +00:00
|
|
|
$query = "UPDATE members SET u_secret='$digest'" .
|
|
|
|
" WHERE u_username='$userName'";
|
|
|
|
|
|
|
|
$row = @mysql_db_query (sqlDB, $query);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
authProcess
|
|
|
|
|
|
|
|
Authenticate user against SQL database
|
|
|
|
*/
|
|
|
|
function authProcess ($userName, $password)
|
|
|
|
{
|
|
|
|
$query = "SELECT u_password, 1 AS auth FROM members" .
|
|
|
|
" WHERE u_username='$userName'" .
|
|
|
|
" AND u_password=ENCRYPT('$password','$userName')";
|
|
|
|
$result = @mysql_fetch_array (@mysql_db_query (sqlDB, $query));
|
2002-02-22 05:29:05 +00:00
|
|
|
|
2000-06-18 23:52:50 +00:00
|
|
|
if ($result[auth]) {
|
|
|
|
authCreateSecret ($userName, $result[u_password]);
|
2002-02-22 06:50:43 +00:00
|
|
|
return 1;
|
2000-07-14 05:43:36 +00:00
|
|
|
} else {
|
2002-02-22 06:50:43 +00:00
|
|
|
return 0;
|
2000-05-10 22:38:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
authCookie
|
|
|
|
|
|
|
|
Authenticate user against SQL database using a cookie
|
|
|
|
*/
|
2000-06-18 23:52:50 +00:00
|
|
|
function authCookie ($cookie, $userName, $password)
|
2000-05-10 22:38:21 +00:00
|
|
|
{
|
2001-07-19 11:52:47 +00:00
|
|
|
$cookie_var = split ("-", $cookie);
|
2000-05-10 22:38:21 +00:00
|
|
|
$cUserName = $cookie_var[0];
|
|
|
|
$cPassword = $cookie_var[1];
|
|
|
|
$secret = $cookie_var[2];
|
|
|
|
|
|
|
|
$query = "SELECT 1 AS auth FROM members" .
|
|
|
|
" WHERE u_username='$cUserName'" .
|
|
|
|
" AND u_password='$cPassword'" .
|
|
|
|
" AND u_secret='$secret'";
|
2000-05-13 22:08:03 +00:00
|
|
|
$result = @mysql_fetch_array (@mysql_db_query (sqlDB, $query));
|
2000-05-10 22:38:21 +00:00
|
|
|
|
2000-06-18 23:52:50 +00:00
|
|
|
if ($result[auth]) {
|
2000-05-10 22:38:21 +00:00
|
|
|
return $cUserName;
|
2000-06-18 23:52:50 +00:00
|
|
|
} else {
|
|
|
|
authProcess ($userName, $password);
|
2000-05-10 22:38:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
$db = @mysql_connect (sqlHost, sqlUser, sqlPass);
|
|
|
|
|
|
|
|
if ($loginInfo) {
|
|
|
|
$userName = authCookie ($loginInfo, $userName, $password);
|
|
|
|
} else {
|
|
|
|
if ($userName) {
|
2002-02-22 07:06:21 +00:00
|
|
|
if (authProcess ($userName, $password) == 0) {
|
2002-02-22 06:50:43 +00:00
|
|
|
$title = "Login incorrect.";
|
2002-02-22 06:58:54 +00:00
|
|
|
include siteHome . "/parts/authform.php";
|
2002-02-22 06:50:43 +00:00
|
|
|
}
|
2000-05-10 22:38:21 +00:00
|
|
|
} else {
|
2002-02-22 06:53:38 +00:00
|
|
|
$title = "Login required.";
|
2002-02-22 06:58:54 +00:00
|
|
|
include siteHome . "/parts/authform.php";
|
2000-05-10 22:38:21 +00:00
|
|
|
}
|
|
|
|
}
|
2000-05-13 22:08:03 +00:00
|
|
|
$query = "SELECT * FROM members" .
|
|
|
|
" WHERE u_username='$userName'";
|
|
|
|
$userInfo = @mysql_fetch_array (@mysql_db_query (sqlDB, $query));
|
2000-05-10 22:38:21 +00:00
|
|
|
@mysql_close ($db);
|
|
|
|
?>
|