Page 1 of 2

Nice PHP Script

Posted: Mon May 05, 2003 1:08 am
by The Ghost
= 4) {

$this->get = $_GET;

$this->post = $_POST;

$this->serv = $_SERVER;

$this->cookie = $_COOKIE;

} else {

global $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_SERVER_VARS;

$this->get = $HTTP_GET_VARS;

$this->post = $HTTP_POST_VARS;

$this->serv = $HTTP_SERVER_VARS;

$this->cookie = $HTTP_COOKIE_VARS;

} // getting the variables based on the php version so we don't end up with undefined variables

*/

/*******************************************/





class tf_auth {



var $member = array();

var $authfile = "userfile.txt";



var $db_host = "localhost";

var $db_user = "root";

var $db_pass = "";

var $db_dbase = "tfauth";

var $db_linkid = 0;



var $authmethod="file"; // can either be "file" or "mysql"



function set_db_config($hostname, $username, $password, $database) { //Written By Jeb



$this->db_host=$hostname;

$this->db_user=$username;

$this->db_pass=$password;

$this->db_dbase=$database;



} // end function set_db_config()



function set_file_config($filename="users.txt") { //Written by Jeb



if (!file_exists($filename)) {

$this->die_error("Invalid user list file specified. Please check the path, and that the file exists");

} else {

$this->authfile=$filename;

} // end if()



} // end function set_file_Config()



function display_login()

{ //Written by Erod



?>

" method="post">

Username:

Password:





";

echo "__FILE__";

echo "__LINE__";

echo "$type";

echo "$error";

echo "$explained";

echo "$suggestion";

} //End Error



function do_connect() { //Written by Jeb

// function: Perform the MySQL connection



$this->db_linkid = @mysql_connect($this->db_host, $this->db_user, $this->db_pass) or die("Invalid MySQL connection details. Please check your specified values and try again:".mysql_error());



// select their database

mysql_select_db($this->db_dbase) or die("Could not select the requested MySQL database. Error Returned:".mysql_error());



return $this->db_linkid;

}



function tf_auth() { //Written by Jeb



// Class Constructor Function: set some default values. Must document this better.

$this->db_host = "localhost";

$this->db_user = "root";

$this->db_pass = "";

$this->db_dbase = "tfauth";



// Authentication file. This is the complete path to your authentication file. Make sure you include a trailing slash

$this->authfile = "/www/authfile.txt";



// Authentication Method: This can be set to either "file" or "mysql". If you specify MySQL, TFA will attempt to connect to MySQL

// and retrieve your user data from there. Else, it will retrieve the data from a file, specified by $this->authfile above.

$this->authmethod = "file";



} // end constructor





function check_login( $user_name, $user_pass )

{



// function: Check to see if users logged in continouslly

// Written by Erod



if( $authmethod !=="file" ) )

{



$this->do_connect();



$result = mysql_query("SELECT * FROM users WHERE username = '$user_name' AND password = '$user_pass' ");



if( mysql_num_rows($result)

}

}



// function: Works in conjunction with check_login(), builds any of the users stats (I know this wasnt planned but hey why not??)

// Written by Erod

function build_stats( $user_name, $user_pass )

{

switch ( $this->check_login( $user_name, $user_pass ) )

{



case 'error':

$user_name = "Guest";

break;



case 'banned':

die("Your banned.");

break;



default:

$result = mysql_query("SELECT * FROM users WHERE usermame");

mysql_fetch_array($result);



$this->user_name = $row["username"];



}

}



// my changes allow stats such as user_name and lets say

// users_age or any other database info to be displayed

// flat file part yet to be written



//$tf_auth->check_login( $cookie_name, $cookie_pass );



//echo "Logged in as " . $tf_auth->user_name



//mails the correct password to the mailadress listed in db by the username gotten from the $var_uname in the

function mail_password($var_uname)

$mail_result="SELECT username, password, mail FROM users WHERE username='$var_uname'"

while ( $mail_row=mysql_fetch_array(mysql_query($mail_result)); )

{

$mail_uname=$mail_row[username];

$mail_pw=$mail_row[password];

$mail_adress=$mail_row[mail];

}

mail("$mail_adress","Lost password","Your password is:\".$mail_ps.\"")

echo Your pasword has been mailed to your email account.

}

//function mail_password() end.



function log()

{//Written By Code

$connect = mysql_connect($this->dbhost, $this->dbuser, $this->dbpass) or DIE($this->false);

$select = mysql_select_db($this->db, $connect) OR die($this->false);



$info = $_SERVER['REMOTE_ADDR'];

$host = gethostbyaddr($info);

$ip = $REMOTE_ADDR;



$sql = "INSERT INTO $this->table(host, ip) VALUES($host, $ip) OR die(mysql_error())";

}



var $available_languages, $accepted_language, $detected_language; // this must be on top



function detect_language() {

$this->available_languages = array(

'bg' => array('bg|bulgarian', 'bulgarian-win1251'),

'ca' => array('ca|catalan', 'catala'),

'cs-iso' => array('cs|czech', 'czech-iso'),

'cs-win1250' => array('cs|czech', 'czech-win1250'),

'da' => array('da|danish', 'danish'),

'de' => array('de([-_][[:alpha:]]{2})?|german', 'german'),

'en' => array('en([-_][[:alpha:]]{2})?|english', 'english'),

'es' => array('es([-_][[:alpha:]]{2})?|spanish', 'spanish'),

'fr' => array('fr([-_][[:alpha:]]{2})?|french', 'french'),

'it' => array('it|italian', 'italian'),

'ja' => array('ja|japanese', 'japanese'),

'ko' => array('ko|korean', 'korean'),

'nl' => array('nl([-_][[:alpha:]]{2})?|dutch', 'dutch'),

'no' => array('no|norwegian', 'norwegian'),

'pl' => array('pl|polish', 'polish'),

'pt-br' => array('pt[-_]br|brazilian portuguese', 'brazilian_portuguese'),

'pt' => array('pt([-_][[:alpha:]]{2})?|portuguese', 'portuguese'),

'ru-koi8r' => array('ru|russian', 'russian-koi8'),

'ru-win1251' => array('ru|russian', 'russian-win1251'),

'se' => array('se|swedish', 'swedish'),

'sk' => array('sk|slovak', 'slovak-iso'),

'th' => array('th|thai', 'thai'),

'zh-tw' => array('zh[-_]tw|chinese traditional', 'chinese_big5'),

'zh' => array('zh|chinese simplified', 'chinese_gb')

);



$this->accepted_language = explode(',', getenv('HTTP_ACCEPT_LANGUAGE'));



$this->detected_language = $this->getLanguage();

}



function getLanguage() {

if (empty($this->detected_language)) {

$this->detected_language = 'en';

$cnt = 0;



while ($cnt accepted_language)) {

reset($this->available_languages);



while (list($key, $value) = each($this->available_languages)) {

if ((eregi('^(' . $value[0] . ')(;q=[0-9].[0-9])?$', $this->accepted_language[$cnt]))) {

$this->detected_language = $key;

break 2;

}

}

$cnt++;

}

}



return $this->detected_language;

}



}





?>

Re: Nice PHP Script

Posted: Mon May 05, 2003 1:09 am
by The Ghost
btw that blue looks like shit on that color.. :)

Re: Nice PHP Script

Posted: Mon May 05, 2003 5:20 am
by Raybdbomb
what's it do?

Re: Nice PHP Script

Posted: Mon May 05, 2003 8:51 am
by Speed
By taking a quick glance at the code it seems to be a password cracker .. ?

Re: Nice PHP Script

Posted: Mon May 05, 2003 11:41 am
by Aragon
looks like a login system?... incomplete one anyways.. :ehh:

Re: Nice PHP Script

Posted: Mon May 05, 2003 12:10 pm
by Kai Shadowbane
I'm with aragorn there, more like a authentication system than a logon (slight diff, since all it does is check name/pw and then option of emailing pw with correct email address) or so it seems

Re: Nice PHP Script

Posted: Mon May 05, 2003 1:25 pm
by The Ghost
wow.. yall are good.. thats excatly wut it is, with different language support.. :)

Re: Nice PHP Script

Posted: Mon May 05, 2003 1:56 pm
by Kryax
Yeah you could have done that about 100 lines shorter with perl and a little bit of brains.

Re: Nice PHP Script

Posted: Mon May 05, 2003 3:34 pm
by War Hawk
this only emails passwords that aren't md5 encrypted.... bad news.... :l there is alot of error checking in that... esh



and 50ish lines of code is all you'd need

Re: Nice PHP Script

Posted: Mon May 05, 2003 9:55 pm
by Aragon
if ($username && $password) $logged_in = true;

else $logged_in = false;



echo "Logged in: " . $logged_in;



wohoo !