• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Some AAC functions

Nostradamus

Member
Joined
Jun 2, 2007
Messages
219
Reaction score
6
My friend requested some functions so i decided to make and post to everyone.
Please note that i have been idle in PHP for one year or more.

Here it is:

PHP:
<?php
	class MySQL 
	{
		var $host;
		var $user;
		var $pass;
		var $db;

		function connect() 
		{
			$cn = mysql_connect($this->sql['host'], $this->sql['user'], $this->sql['pass']);
			mysql_select_db($this->sql['db']);
		}

		function disconnect() 
		{
			mysql_close($this->$cn);
		}

		function __construct(&$sql) 
		{
			$this->sql = $sql;
		}
		
	}
	
	class AAC
	{
		
		function doGenerateAccount() 
		{
			do 
			{
				$rand = rand(100000, 9999999);
				$query = mysql_query("SELECT `id` FROM accounts WHERE id = '$rand'");
			}
			while(mysql_num_rows($query) > 0));
			return $rand;
		}
		
		function doCheckAccount($account) 
		{
			$query = mysql_query("SELECT `id` FROM `accounts` WHERE id = '$account'");
			if (mysql_num_rows($query) > 0) 
				return true;
			else 
				return false;
		}
		
		function doCheckLogin($account, $password) 
		{
			$query = mysql_query("SELECT * FROM `accounts` WHERE `id` = '$account' AND `password` = '$password'");
			if (mysql_num_rows($query) > 0) 
				return true;
			else
				return false;
		}
		
		function doChangePassword($account, $oldpass, $newpass) 
		{
			$check = mysql_query("SELECT `password` FROM `accounts` WHERE `password` = '$oldpass'");
			if (mysql_num_rows($check) > 0) 
			{
				$make = mysql_query("UPDATE `accounts` SET `password` = `$newpass` WHERE `id` = `$account`");
				return true;
			}
			else 
				return false;	
		}
		
		function doCreateAccount($email, $account, $password) 
		{
			if ($this->doCheckAccount($account) == false) 
			{
				if (eregi('^[0-9]+$', $account) || eregi('^[-_a-z0-9 ]+$', $password) || eregi('^[-_a-z0-9]+(\\.[-_a-z0-9]+)*\\@([-a-z0-9]+\\.)*([a-z]{2,4})$', $email)) 
				{
					if (strlen($account) >= 6 || strlen($account) <= 7 || strlen($password) >= 3 || strlen($password) <= 20) 
					{
						$make = mysql_query("INSERT INTO `accounts` VALUES ($account, $password, 0, 0, '', $email, '', 0");
						return true;
					}
				}
			}
			else 
				return false;
		}
	}
?>
 
Last edited:
did you test?

seems:
while
{
mysql_num_rows($query) > 0);
}
would cause parsing problems. I think you want:
Code:
while(mysql_num_rows($query) > 0);
 
@Vagabond
This is not a while loop but a do while loop

@Kiper
What do you mean with it?
 
Last edited:
@Vagabond
This is not a while loop but a do while loop

@Kiper
What do you mean with it?

It change the password of every account, and your do while loop doesn't have correct form, should be do{ /* do something here */ }while(statement); not do{ /* do something here */ } while { statement }
 
@Vagabond
This is not a while loop but a do while loop

you think I was not aware of that? :p

the proper syntax for do..while in C/C++ is:
PHP:
do {

} while(condition);
It might be different in PHP though, but I doubt it since PHP is a c-syntax language...

edit: Tala~ beat me to it. shoulda read the rest of the posts. x]
 
Last edited:
My friend requested some functions so i decided to make and post to everyone.
Please note that i have been idle in PHP for one year or more.

Here it is:

PHP:
<?php
	class MySQL 
	{
		var $host;
		var $user;
		var $pass;
		var $db;

		function connect() 
		{
			$cn = mysql_connect($this->sql['host'], $this->sql['user'], $this->sql['pass']);
			mysql_select_db($this->sql['db']);
		}

		function disconnect() 
		{
			mysql_close($this->$cn);
		}

		function __construct(&$sql) 
		{
			$this->sql = $sql;
		}
		
	}
	
	class AAC
	{
		
		function doGenerateAccount() 
		{
			do 
			{
				$rand = rand(100000, 9999999);
				$query = mysql_query("SELECT `id` FROM accounts WHERE id = '$rand'");
			}
			while(mysql_num_rows($query) > 0));
			return $rand;
		}
		
		function doCheckAccount($account) 
		{
			$query = mysql_query("SELECT `id` FROM `accounts` WHERE id = '$account'");
			if (mysql_num_rows($query) > 0) 
				return true;
			else 
				return false;
		}
		
		function doCheckLogin($account, $password) 
		{
			$query = mysql_query("SELECT * FROM `accounts` WHERE `id` = '$account' AND `password` = '$password'");
			if (mysql_num_rows($query) > 0) 
				return true;
			else
				return false;
		}
		
		function doChangePassword($account, $oldpass, $newpass) 
		{
			$check = mysql_query("SELECT `password` FROM `accounts` WHERE `password` = '$oldpass'");
			if (mysql_num_rows($check) > 0) 
			{
				$make = mysql_query("UPDATE `accounts` SET `password` = `$newpass` WHERE `account` = `$account`");
				return true;
			}
			else 
				return false;	
		}
		
		function doCreateAccount($email, $account, $password) 
		{
			if ($this->doCheckAccount($account) == false) 
			{
				if (eregi('^[0-9]+$', $account) || eregi('^[-_a-z0-9 ]+$', $password) || eregi('^[-_a-z0-9]+(\\.[-_a-z0-9]+)*\\@([-a-z0-9]+\\.)*([a-z]{2,4})$', $email)) 
				{
					if (strlen($account) >= 6 || strlen($account) <= 7 || strlen($password) >= 3 || strlen($password) <= 20) 
					{
						$make = mysql_query("INSERT INTO `accounts` VALUES ($account, $password, 0, 0, '', $email, '', 0");
						return true;
					}
				}
			}
			else 
				return false;
		}
	}
?>

I think it isn't made by you! :S

and...

for what is these variables?
PHP:
		var $host;
		var $user;
		var $pass;
		var $db;

and...

PHP4 is dead...

the 'var' isn't used anymore...
use:
PHP:
private $host, $user, $pass, $db;

and you mixed php4 with 5...
function __construct() is only for php5 + ...
 
Last edited:
@diorgesl

Don't say shit.
Search in all foruns related with OpenTibia and see if it is ripping. -.-

And thanks to saying me about, the 'vars'.

And i know that constructors and destructors is not only for php 5 (php6 is yet available, check this

And what's the point of using functions for only php5?
PHP4 is dead correctly, but only the development of it, doesn't means that all codes made in it, will Stop work...
 
Last edited:
This line:
$make = mysql_query("UPDATE `accounts` SET `password` = `$newpass` WHERE `account` = `$account`");
is still not correct, or perhaps it is in other database structures but from what I can remember in the official one, the account number field is called 'id' and not 'account'.
 
@diorgesl

Don't say shit.
Search in all foruns related with OpenTibia and see if it is ripping. -.-

And thanks to saying me about, the 'vars'.

And i know that constructors and destructors is not only for php 5 (php6 is yet available, check this

And what's the point of using functions for only php5?
PHP4 is dead correctly, but only the development of it, doesn't means that all codes made in it, will Stop work...

lawl...
if you write a script in php4 it should be only php4, dont mix with php5...
about the constructors and destructors... as I said its for php5+... Read my post!

and about your script...
you should make a tuto to explain how to use... coz too many people dont know how to use OOP.
 
Last edited:
Back
Top