<?PHP
// This file holds data on authentication
$auth_ucookie = "X7C2U";
$auth_pcookie = "X7C2P";
$auth_register_link = "../register.php";
$auth_disable_guest = false;
// Include the phpfusion cooookie
include("../config.php");
// Init a new DB session to grab the cookie name
$phpfusion = new x7chat_db($db_host,$db_user,$db_pass,$db_name);
session_start();
// This next line of code is straight from e107
@list($uid, $upw) = (@$_COOKIE['fusion_user'] ? @explode(".", $_COOKIE['fusion_user']) : @explode(".", $_SESSION['fusion_user']));
if(@$uid>0){
// They are logged into phpfusion, do a pass comparison
$query = $phpfusion->DoQuery("SELECT user_name,user_password,user_level FROM {$db_prefix}users WHERE user_id={$uid}");
$row = $phpfusion->Do_Fetch_row($query);
$_COOKIE[$auth_ucookie] = $row[0];
$_COOKIE[$auth_pcookie] = $row[1];
}
function auth_encrypt($data){
return md5($data);
}
function auth_getpass($auth_ucookie){
GLOBAL $db,$prefix,$phpfusion,$db_prefix,$g_default_settings,$txt,$x7c,$uid;
$query = $phpfusion->DoQuery("SELECT user_password FROM {$db_prefix}users WHERE user_name='".$_COOKIE[$auth_ucookie]."'");
$password = $phpfusion->Do_Fetch_Row($query);
if($password[0] != ""){
$query = $db->DoQuery("SELECT * FROM {$prefix}users WHERE username='".$_COOKIE[$auth_ucookie]."'");
$row = $db->Do_Fetch_Row($query);
if($row[0] == ""){
// Create an X7 Chat account for them.
$query = $phpfusion->DoQuery("SELECT user_email,user_level FROM {$db_prefix}users WHERE user_id={$uid}");
$row = $phpfusion->Do_Fetch_row($query);
$email = $row[0];
$userlevel = $row[1];
$time = time();
$ip = $_SERVER['REMOTE_ADDR'];
$set_userlevel = "Registered User";
if($userlevel==103) $set_userlevel = "Administrator";
$db->DoQuery("INSERT INTO {$prefix}users (id,username,password,email,status,user_group,time,settings,hideemail,ip) VALUES('0','$_COOKIE[$auth_ucookie]','$password[0]','{$email}','$txt[150]','{$set_userlevel}','$time','{$g_default_settings}','0','$ip')");
}
}
return $password[0];
}
function change_pass($user,$newpass){
GLOBAL $phpfusion,$db_prefix;
$newpass = auth_encrypt($newpass);
$phpfusion->DoQuery("UPDATE {$db_prefix}users SET user_password='$newpass' WHERE user_name='$user'");
}
?>
|