[Release] Simple PHP Register PHP 

WooAF you can say this is "insecure" "insecure" all you want but try to SQL inject you aren't going to be able to.

Let me clear up what are you confused about WooAF, you are thinking I am just tossing $_POST['password'] into the DB before checking it at all. But I am, if you look at the long if statement you will see
PHP:
preg_replace("/[^a-zA-Z\d ]/", "", $_POST['password']) != $_POST['password']
What this is doing is replacing everything that isn't a-z,A-Z,0-9 with nothing and if that isn't the exact same thing as $_POST['password'] it will error.

Hope this helps you understand PHP a bit more, friend.

PHP:
<?php
$link = mssql_connect('COMPUTER\\iPlayWarZ', 'sa', 'password');
$selectdb = mssql_select_db("WarZ");
if (!$link || !$selectdb){
    die('DB Issue');
}

if(isset($_POST['Submit'])){
    /* ugly but it works */
    if(empty($_POST['email']) || empty($_POST['password']) || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) || preg_replace("/[^a-zA-Z\d ]/", "", $_POST['password']) != $_POST['password'] || strlen($_POST['password']) > 50){ //Since I don't know what the max password size is you should change this.
        die("Something went wrong.");
    }
    $query = mssql_query("SELECT `email` FROM Accounts WHERE email = '".$_POST['email']."'"); //No need to select EVERYTHING from that row.
    $query = mssql_num_rows($query);
    if($query > 0){
        die("Email is already in-use. Please use a different one.");
    }
    else{
        mssql_query("EXEC WZ_ACCOUNT_CREATE '".$_SERVER['REMOTE_ADDR']."', '".$_POST['email']."', '".$_POST['password']."', 0, 0, 0");
        die("Account created");
    }
}
?>
<!--
This is only a sample script, you can remove, edit, what you want.
-->
<form method="post">
<center>
<fieldset>
<legend>Register</legend>

<!-- Email -->
<label for='email' >Email Address*:</label>
<input type='text' name='email' maxlength="50" /><br>

<!-- Password -->
<label for='password' >Password*:</label>
<input type='password' name='password' maxlength="50" /><br>

<!-- Submit -->
<input type='submit' name='Submit' value='Register' />
</fieldset>
</center>
</form>
 
Last edited:
WooAF you can say this is "insecure" "insecure" all you want but try to SQL inject you aren't going to be able to.

Let me clear up what are you confused about WooAF, you are thinking I am just tossing $_POST['password'] into the DB before checking it at all. But I am, if you look at the long if statement you will see
PHP:
preg_replace("/[^a-zA-Z\d ]/", "", $_POST['password']) != $_POST['password']
What this is doing is replacing everything that isn't a-z,A-Z,0-9 with nothing and if that isn't the exact same thing as $_POST['password'] it will error.

Hope this helps you understand PHP a bit more, friend.

PHP:
<?php
$link = mssql_connect('COMPUTER\\iPlayWarZ', 'sa', 'password');
$selectdb = mssql_select_db("WarZ");
if (!$link || !$selectdb){
    die('DB Issue');
}

if(isset($_POST['Submit'])){
    /* ugly but it works */
    if(empty($_POST['email']) || empty($_POST['password']) || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) || preg_replace("/[^a-zA-Z\d ]/", "", $_POST['password']) != $_POST['password'] || strlen($_POST['password']) > 50){ //Since I don't know what the max password size is you should change this.
        die("Something went wrong.");
    }
    $query = mssql_query("SELECT `email` FROM Accounts WHERE email = '".$_POST['email']."'"); //No need to select EVERYTHING from that row.
    $query = mssql_num_rows($query);
    if($query > 0){
        die("Email is already in-use. Please use a different one.");
    }
    else{
        mssql_query("EXEC WZ_ACCOUNT_CREATE '".$_SERVER['REMOTE_ADDR']."', '".$_POST['email']."', '".$_POST['password']."', 0, 0, 0");
        die("Account created");
    }
}
?>
<!--
This is only a sample script, you can remove, edit, what you want.
-->
<form method="post">
<center>
<fieldset>
<legend>Register</legend>

<!-- Email -->
<label for='email' >Email Address*:</label>
<input type='text' name='email' maxlength="50" /><br>

<!-- Password -->
<label for='password' >Password*:</label>
<input type='password' name='password' maxlength="50" /><br>

<!-- Submit -->
<input type='submit' name='Submit' value='Register' />
</fieldset>
</center>
</form>

It can be bypassed. Using that method to clean inputs is just a way for noobs to replace a function that has already been implemented. preg_replace() cannot match all characters that can be injected, it can only replace on the byte level, leaving many vulnerabilities.
 
REGISTER WITH MD5 + HASH(SALT)

PHP:
<?php
	
	$email = trim($_POST['email']);
	$senha = trim($_POST['senha']);
	$senha2 = trim($_POST['senha2']);
	date_default_timezone_set('America/Sao_Paulo');	$dataCadastro = date('Y-m-d H:i:s');
	

	if($senha != $senha2) {
		header("location: faq.php?t=1&msg=Erro: As senhas devem ser iguais!");
		exit;
	}
	

	if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
	
		header("location: faq.php?t=1&msg=Erro: Digite um e-mail válido!");
		exit;
	
	}
	
	include("teste/class/mssql.class.php");
	include("teste/inc/config.php");
	$mssql = new Mssql;
	$mssql->connect($host,$username,$password);
	$mssql->selectDb('warz');
	$salt = 'g5sc4gs1fz0h';
	
	$hash = md5($salt.$senha);
	$senha = $hash;
        
        $sql = "SELECT * FROM Accounts WHERE email = '$email'";
        $verifica = $mssql->query($sql);
        
        if(mssql_num_rows($verifica) > 0) {
                header("location: faq.php?t=1&msg=Erro: Este e-mail já esta em uso, utilize outro!");
		exit;
        }
	
	
global $dataCadastro;
	$sql = "use warz INSERT INTO Accounts (email, MD5Password, dateregistered, AccountStatus, ReferralID) VALUES ('$email', '$senha', '$dataCadastro', 100, 0)";
	$insert = $mssql->query($sql);
	
	
	function mssql_insert_id() {
		$id = false;
		$res = mssql_query('SELECT @@identity AS id');
		if ($row = mssql_fetch_row($res)) {
			$id = trim($row[0]);
		}
		mssql_free_result($res);
		return $id;
	}
	
	$lastId = mssql_insert_id();
	
	if($insert) {
	

		
		global $dataCadastro;
		$sql = "use warz INSERT INTO UsersData(CustomerID, IsDeveloper, AccountType, AccountStatus, GamePoints, GameDollars, dateregistered, ClanID, ClanRank, BanCount, CharsCreated, GameServerId, lastjoineddate, lastgamedate) 
				VALUES ('$lastId', 0, '2', 100, 0, 0, '$dataCadastro', 0, 99, 0, 1, 0, '$dataCadastro', '$dataCadastro')";
					
		
		$insert = $mssql->query($sql);
		
		if($insert){
			header("location: faq.php?t=0&msg=Conta cadastrada com sucesso!");
		}else{
			header("location: faq.php?t=1&msg=Erro: Ocorreu um erro ao cadastrar sua conta!");
		}
		
		
	}else{
		header("location: faq.php?t=1&msg=Erro: Ocorreu um erro ao cadastrar sua conta!");
	}
	

?>


REGISTER WITH CHECK KEY
PHP:
<?php
	
	$email = trim($_POST['email']);
	$senha = trim($_POST['senha']);
	$senha2 = trim($_POST['senha2']);
	$key = trim($_POST['key']);
	date_default_timezone_set('America/Sao_Paulo');	$dataCadastro = date('Y-m-d H:i:s');
	

	if($senha != $senha2) {
		header("location: faq.php?t=1&msg=Erro: As senhas devem ser iguais!");
		exit;
	}
	

	if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
	
		header("location: faq.php?t=1&msg=Erro: Digite um e-mail válido!");
		exit;
	
	}
	
	include("teste/class/mssql.class.php");
	include("teste/inc/config.php");
	$mssql = new Mssql;
	$mssql->connect($host,$username,$password);
	$mssql->selectDb('warz');
	$salt = 'g5sc4gs1fz0h';
	
	$hash = md5($salt.$senha);
	$senha = $hash;
        

        $sql = "SELECT * FROM Accounts WHERE email = '$email'";
        $verifica = $mssql->query($sql);
        
        if(mssql_num_rows($verifica) > 0) {
                header("location: faq.php?t=1&msg=Erro: Este e-mail já esta em uso, utilize outro!");
		exit;
        }
	
	$aa = mssql_fetch_array($mssql->query("use breezenet SELECT Count(*) as count FROM WarZSerials Where SerialKey = '$key' And IsUsed = '1'"));
	
	if($aa['count'] >0) {

	$getinfoKey = mssql_fetch_array($mssql->query("use breezenet SELECT SerialType FROM WarZSerials Where SerialKey = '$key' And IsUsed = '1'"));
	
global $dataCadastro;
	$sql = "use warz INSERT INTO Accounts (email, MD5Password, dateregistered, AccountStatus, ReferralID) VALUES ('$email', '$senha', '$dataCadastro', 100, 0)";
	$insert = $mssql->query($sql);
	
	

	function mssql_insert_id() {
		$id = false;
		$res = mssql_query('SELECT @@identity AS id');
		if ($row = mssql_fetch_row($res)) {
			$id = trim($row[0]);
		}
		mssql_free_result($res);
		return $id;
	}
	
	$lastId = mssql_insert_id();
	
	if($insert) {
	

		
		global $dataCadastro;
		$sql = "use warz INSERT INTO UsersData(CustomerID, IsDeveloper, AccountType, AccountStatus, GamePoints, GameDollars, dateregistered, ClanID, ClanRank, BanCount, CharsCreated, GameServerId, lastjoineddate, lastgamedate) 
				VALUES ('$lastId', 0, '$getinfoKey[SerialType]', 100, 800, 1000, '$dataCadastro', 0, 99, 0, 1, 0, '$dataCadastro', '$dataCadastro')";
				
		$mssql->query("use breezenet update WarZSerials set IsUsed = 0 where SerialKey = '$key'");
		
		
		$insert = $mssql->query($sql);
		
		if($insert){
			header("location: faq.php?t=0&msg=Conta cadastrada com sucesso!");
		}else{
			header("location: faq.php?t=1&msg=Erro: Ocorreu um erro ao cadastrar sua conta!");
		}
		
		
	}else{
		header("location: faq.php?t=1&msg=Erro: Ocorreu um erro ao cadastrar sua conta!");
	}
	
	 }else {
		header("location: faq.php?t=1&msg=Erro: Sua KEY não é válida!");
	} 

?>


MSSQL.CLASS.PHP

PHP:
<?php

Class Mssql {

	function connect ($host,$username,$password) {

			mssql_connect($host,$username,$password);

	}

	function selectDb ($value) {

		mssql_select_db($value);

	}

	function query($value) {

		return mssql_query($value);
	}

	function __desctruct() {

		mssql_close();
	}

}
?>


CONFIG.PHP

PHP:
<?php

# MSSQL CONFIGURATION

$host = "";
$username = "root";
$password = "";
$database ="breezenet";
 
REGISTER WITH MD5 + HASH(SALT)

PHP:
<?php
	
	$email = trim($_POST['email']);
	$senha = trim($_POST['senha']);
	$senha2 = trim($_POST['senha2']);
	date_default_timezone_set('America/Sao_Paulo');	$dataCadastro = date('Y-m-d H:i:s');
	

	if($senha != $senha2) {
		header("location: faq.php?t=1&msg=Erro: As senhas devem ser iguais!");
		exit;
	}
	

	if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
	
		header("location: faq.php?t=1&msg=Erro: Digite um e-mail válido!");
		exit;
	
	}
	
	include("teste/class/mssql.class.php");
	include("teste/inc/config.php");
	$mssql = new Mssql;
	$mssql->connect($host,$username,$password);
	$mssql->selectDb('warz');
	$salt = 'g5sc4gs1fz0h';
	
	$hash = md5($salt.$senha);
	$senha = $hash;
        
        $sql = "SELECT * FROM Accounts WHERE email = '$email'";
        $verifica = $mssql->query($sql);
        
        if(mssql_num_rows($verifica) > 0) {
                header("location: faq.php?t=1&msg=Erro: Este e-mail já esta em uso, utilize outro!");
		exit;
        }
	
	
global $dataCadastro;
	$sql = "use warz INSERT INTO Accounts (email, MD5Password, dateregistered, AccountStatus, ReferralID) VALUES ('$email', '$senha', '$dataCadastro', 100, 0)";
	$insert = $mssql->query($sql);
	
	
	function mssql_insert_id() {
		$id = false;
		$res = mssql_query('SELECT @@identity AS id');
		if ($row = mssql_fetch_row($res)) {
			$id = trim($row[0]);
		}
		mssql_free_result($res);
		return $id;
	}
	
	$lastId = mssql_insert_id();
	
	if($insert) {
	

		
		global $dataCadastro;
		$sql = "use warz INSERT INTO UsersData(CustomerID, IsDeveloper, AccountType, AccountStatus, GamePoints, GameDollars, dateregistered, ClanID, ClanRank, BanCount, CharsCreated, GameServerId, lastjoineddate, lastgamedate) 
				VALUES ('$lastId', 0, '2', 100, 0, 0, '$dataCadastro', 0, 99, 0, 1, 0, '$dataCadastro', '$dataCadastro')";
					
		
		$insert = $mssql->query($sql);
		
		if($insert){
			header("location: faq.php?t=0&msg=Conta cadastrada com sucesso!");
		}else{
			header("location: faq.php?t=1&msg=Erro: Ocorreu um erro ao cadastrar sua conta!");
		}
		
		
	}else{
		header("location: faq.php?t=1&msg=Erro: Ocorreu um erro ao cadastrar sua conta!");
	}
	

?>


REGISTER WITH CHECK KEY
PHP:
<?php
	
	$email = trim($_POST['email']);
	$senha = trim($_POST['senha']);
	$senha2 = trim($_POST['senha2']);
	$key = trim($_POST['key']);
	date_default_timezone_set('America/Sao_Paulo');	$dataCadastro = date('Y-m-d H:i:s');
	

	if($senha != $senha2) {
		header("location: faq.php?t=1&msg=Erro: As senhas devem ser iguais!");
		exit;
	}
	

	if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
	
		header("location: faq.php?t=1&msg=Erro: Digite um e-mail válido!");
		exit;
	
	}
	
	include("teste/class/mssql.class.php");
	include("teste/inc/config.php");
	$mssql = new Mssql;
	$mssql->connect($host,$username,$password);
	$mssql->selectDb('warz');
	$salt = 'g5sc4gs1fz0h';
	
	$hash = md5($salt.$senha);
	$senha = $hash;
        

        $sql = "SELECT * FROM Accounts WHERE email = '$email'";
        $verifica = $mssql->query($sql);
        
        if(mssql_num_rows($verifica) > 0) {
                header("location: faq.php?t=1&msg=Erro: Este e-mail já esta em uso, utilize outro!");
		exit;
        }
	
	$aa = mssql_fetch_array($mssql->query("use breezenet SELECT Count(*) as count FROM WarZSerials Where SerialKey = '$key' And IsUsed = '1'"));
	
	if($aa['count'] >0) {

	$getinfoKey = mssql_fetch_array($mssql->query("use breezenet SELECT SerialType FROM WarZSerials Where SerialKey = '$key' And IsUsed = '1'"));
	
global $dataCadastro;
	$sql = "use warz INSERT INTO Accounts (email, MD5Password, dateregistered, AccountStatus, ReferralID) VALUES ('$email', '$senha', '$dataCadastro', 100, 0)";
	$insert = $mssql->query($sql);
	
	

	function mssql_insert_id() {
		$id = false;
		$res = mssql_query('SELECT @@identity AS id');
		if ($row = mssql_fetch_row($res)) {
			$id = trim($row[0]);
		}
		mssql_free_result($res);
		return $id;
	}
	
	$lastId = mssql_insert_id();
	
	if($insert) {
	

		
		global $dataCadastro;
		$sql = "use warz INSERT INTO UsersData(CustomerID, IsDeveloper, AccountType, AccountStatus, GamePoints, GameDollars, dateregistered, ClanID, ClanRank, BanCount, CharsCreated, GameServerId, lastjoineddate, lastgamedate) 
				VALUES ('$lastId', 0, '$getinfoKey[SerialType]', 100, 800, 1000, '$dataCadastro', 0, 99, 0, 1, 0, '$dataCadastro', '$dataCadastro')";
				
		$mssql->query("use breezenet update WarZSerials set IsUsed = 0 where SerialKey = '$key'");
		
		
		$insert = $mssql->query($sql);
		
		if($insert){
			header("location: faq.php?t=0&msg=Conta cadastrada com sucesso!");
		}else{
			header("location: faq.php?t=1&msg=Erro: Ocorreu um erro ao cadastrar sua conta!");
		}
		
		
	}else{
		header("location: faq.php?t=1&msg=Erro: Ocorreu um erro ao cadastrar sua conta!");
	}
	
	 }else {
		header("location: faq.php?t=1&msg=Erro: Sua KEY não é válida!");
	} 

?>


MSSQL.CLASS.PHP

PHP:
<?php

Class Mssql {

	function connect ($host,$username,$password) {

			mssql_connect($host,$username,$password);

	}

	function selectDb ($value) {

		mssql_select_db($value);

	}

	function query($value) {

		return mssql_query($value);
	}

	function __desctruct() {

		mssql_close();
	}

}
?>


CONFIG.PHP

PHP:
<?php

# MSSQL CONFIGURATION

$host = "";
$username = "root";
$password = "";
$database ="breezenet";

Congratz your code is just as exploitable.
 
REGISTER WITH MD5 + HASH(SALT)

PHP:
<?php

$email = trim($_POST['email']);
$senha = trim($_POST['senha']);
$senha2 = trim($_POST['senha2']);
date_default_timezone_set('America/Sao_Paulo');$dataCadastro = date('Y-m-d H:i:s');


if($senha != $senha2) {
header("location: faq.php?t=1&msg=Erro: As senhas devem ser iguais!");
exit;
}


if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {

header("location: faq.php?t=1&msg=Erro: Digite um e-mail válido!");
exit;

}

include("teste/class/mssql.class.php");
include("teste/inc/config.php");
$mssql = new Mssql;
$mssql->connect($host,$username,$password);
$mssql->selectDb('warz');
$salt = 'g5sc4gs1fz0h';

$hash = md5($salt.$senha);
$senha = $hash;
        
        $sql = "SELECT * FROM Accounts WHERE email = '$email'";
        $verifica = $mssql->query($sql);
        
        if(mssql_num_rows($verifica) > 0) {
                header("location: faq.php?t=1&msg=Erro: Este e-mail já esta em uso, utilize outro!");
exit;
        }


global $dataCadastro;
$sql = "use warz INSERT INTO Accounts (email, MD5Password, dateregistered, AccountStatus, ReferralID) VALUES ('$email', '$senha', '$dataCadastro', 100, 0)";
$insert = $mssql->query($sql);


function mssql_insert_id() {
$id = false;
$res = mssql_query('SELECT @@identity AS id');
if ($row = mssql_fetch_row($res)) {
$id = trim($row[0]);
}
mssql_free_result($res);
return $id;
}

$lastId = mssql_insert_id();

if($insert) {



global $dataCadastro;
$sql = "use warz INSERT INTO UsersData(CustomerID, IsDeveloper, AccountType, AccountStatus, GamePoints, GameDollars, dateregistered, ClanID, ClanRank, BanCount, CharsCreated, GameServerId, lastjoineddate, lastgamedate) 
VALUES ('$lastId', 0, '2', 100, 0, 0, '$dataCadastro', 0, 99, 0, 1, 0, '$dataCadastro', '$dataCadastro')";


$insert = $mssql->query($sql);

if($insert){
header("location: faq.php?t=0&msg=Conta cadastrada com sucesso!");
}else{
header("location: faq.php?t=1&msg=Erro: Ocorreu um erro ao cadastrar sua conta!");
}


}else{
header("location: faq.php?t=1&msg=Erro: Ocorreu um erro ao cadastrar sua conta!");
}


?>


REGISTER WITH CHECK KEY
PHP:
<?php

$email = trim($_POST['email']);
$senha = trim($_POST['senha']);
$senha2 = trim($_POST['senha2']);
$key = trim($_POST['key']);
date_default_timezone_set('America/Sao_Paulo');$dataCadastro = date('Y-m-d H:i:s');


if($senha != $senha2) {
header("location: faq.php?t=1&msg=Erro: As senhas devem ser iguais!");
exit;
}


if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {

header("location: faq.php?t=1&msg=Erro: Digite um e-mail válido!");
exit;

}

include("teste/class/mssql.class.php");
include("teste/inc/config.php");
$mssql = new Mssql;
$mssql->connect($host,$username,$password);
$mssql->selectDb('warz');
$salt = 'g5sc4gs1fz0h';

$hash = md5($salt.$senha);
$senha = $hash;
        

        $sql = "SELECT * FROM Accounts WHERE email = '$email'";
        $verifica = $mssql->query($sql);
        
        if(mssql_num_rows($verifica) > 0) {
                header("location: faq.php?t=1&msg=Erro: Este e-mail já esta em uso, utilize outro!");
exit;
        }

$aa = mssql_fetch_array($mssql->query("use breezenet SELECT Count(*) as count FROM WarZSerials Where SerialKey = '$key' And IsUsed = '1'"));

if($aa['count'] >0) {

$getinfoKey = mssql_fetch_array($mssql->query("use breezenet SELECT SerialType FROM WarZSerials Where SerialKey = '$key' And IsUsed = '1'"));

global $dataCadastro;
$sql = "use warz INSERT INTO Accounts (email, MD5Password, dateregistered, AccountStatus, ReferralID) VALUES ('$email', '$senha', '$dataCadastro', 100, 0)";
$insert = $mssql->query($sql);



function mssql_insert_id() {
$id = false;
$res = mssql_query('SELECT @@identity AS id');
if ($row = mssql_fetch_row($res)) {
$id = trim($row[0]);
}
mssql_free_result($res);
return $id;
}

$lastId = mssql_insert_id();

if($insert) {



global $dataCadastro;
$sql = "use warz INSERT INTO UsersData(CustomerID, IsDeveloper, AccountType, AccountStatus, GamePoints, GameDollars, dateregistered, ClanID, ClanRank, BanCount, CharsCreated, GameServerId, lastjoineddate, lastgamedate) 
VALUES ('$lastId', 0, '$getinfoKey[SerialType]', 100, 800, 1000, '$dataCadastro', 0, 99, 0, 1, 0, '$dataCadastro', '$dataCadastro')";

$mssql->query("use breezenet update WarZSerials set IsUsed = 0 where SerialKey = '$key'");


$insert = $mssql->query($sql);

if($insert){
header("location: faq.php?t=0&msg=Conta cadastrada com sucesso!");
}else{
header("location: faq.php?t=1&msg=Erro: Ocorreu um erro ao cadastrar sua conta!");
}


}else{
header("location: faq.php?t=1&msg=Erro: Ocorreu um erro ao cadastrar sua conta!");
}

 }else {
header("location: faq.php?t=1&msg=Erro: Sua KEY não é válida!");
} 

?>


MSSQL.CLASS.PHP

PHP:
<?php

Class Mssql {

function connect ($host,$username,$password) {

mssql_connect($host,$username,$password);

}

function selectDb ($value) {

mssql_select_db($value);

}

function query($value) {

return mssql_query($value);
}

function __desctruct() {

mssql_close();
}

}
?>


CONFIG.PHP

PHP:
<?php

# MSSQL CONFIGURATION

$host = "";
$username = "root";
$password = "";
$database ="breezenet";

Why the **** are you using insert for this with a hash + salt when the procedure have it already ?

4 Beta
 
I deleted the website, got too hectic....
Can someone help me with the API?

I get a WO_API: wrong header: <%@ page language="C#"
 
It can be bypassed. Using that method to clean inputs is just a way for noobs to replace a function that has already been implemented. preg_replace() cannot match all characters that can be injected, it can only replace on the byte level, leaving many vulnerabilities.

Though I don't see much use for preg_replace either, it's definitely not vulnerable (not without /e being in the pattern). It's no different than WooAf's use in functions.php:

PHP:
$value = preg_replace(sql_regcase("/(from|select|insert|delete|where|drop table|show tables|#|\*|--|\\\\)/"),"",$value);

That all being said, both MSSQL and PDO are not supported by Microsoft, there's for that.

Here's a clean register page using sqlsrv (seriously, all of you start using isset right now):
PHP:
<?php
/**
*    © Copyright 2013 Wizkid
*/

// Should match your server's config
define("DATABASE_HOST", "");
define("DATABASE_PORT", 1433); // Don't change unless you know what this actually means
define("DATABASE_USER", "");
define("DATABASE_PASS", "");
define("DATABASE_DB",   "WarZ");

// Feel free to edit
define("WARZ_SERVERNAME", "WarZ");
define("WARZ_MINPASSLENGTH", 6);
define("WARZ_MAXPASSLENGTH", 16);

// You should stop editing now

if (isset($_GET['act']) && $_GET['act'] == "register") {
    if (!isset($_POST['email']) || !isset($_POST['password']) || !isset($_POST['password2'])
        || empty($_POST['email']) || empty($_POST['password']) || empty($_POST['password2'])) {
            echo "All fields are required.<br /><br />";
        }
    else if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
        echo "That doesn't seem to be a valid e-mail address.<br /><br />";
    }
    else if ($_POST['password'] != $_POST['password2']) {
        echo "Password does not match the repeat password.<br /><br />";
    }
    else if (strlen($_POST['password']) < WARZ_MINPASSLENGTH || strlen($_POST['password']) > WARZ_MAXPASSLENGTH) {
        echo "Password does not meet length requimrents. (Min: " . WARZ_MINPASSLENGTH . ", max: " . WARZ_MAXPASSLENGTH . ")<br /><br />";
    }
    else {
        // Let's go
        $pDBLink = sqlsrv_connect(DATABASE_HOST . ", " . DATABASE_PORT, array(
            "Database" => DATABASE_DB,
            "UID"       => DATABASE_USER,
            "PWD"       => DATABASE_PASS));
        
        if ($pDBLink === false) {
            echo "Failed to connect to the database.<br /><br />";
        }
        else if (sqlsrv_has_rows(sqlsrv_query($pDBLink, "SELECT * FROM Accounts WHERE Email = (?)", array(trim($_POST['email']))))) {
            echo "E-mail address already in use.<br /><br />";
        }
        else if (sqlsrv_query($pDBLink, "EXEC WZ_ACCOUNT_CREATE( (?), (?), (?), 0, 0, 0)", 
                array(
                    $_SERVER['REMOTE_ADDR'],
                    trim($_POST['email']),
                    trim($_POST['password'])
                )
            ) === false) {
                echo "Failed to register your account. Please try again later.<br /><br />";
        }
        else {
            echo "Registration was successful.<br /><br />";
        }
    }
}

echo "<b>Register an account at " . WARZ_SERVERNAME . "</b><br /><br />
<form action=\"" . $_SERVER['PHP_SELF'] . "?act=register\" method=\"post\">
    <table width=\"25%\">
        <tr>
            <td width=\"50%\"><b>E-mail address:</b></td>
            <td width=\"50%\"><input type=\"text\" name=\"email\"></td>
        </tr>
        <tr>
            <td width=\"50%\"><b>Password:</b></td>
            <td width=\"50%\"><input type=\"password\" name=\"password\"></td>
        </tr>
        <tr>
            <td width=\"50%\"><b>Repeat password:</b></td>
            <td width=\"50%\"><input type=\"password\" name=\"password2\"></td>
        </tr>
        <tr>
            <td width=\"50%\"></td>
            <td width=\"50%\"><input type=\"submit\" value=\"Register\"></td>
        </tr>        
    </table>
</form>";
?>
 
Last edited:
Fatal error: Call to undefined function sqlsrv_connect() in C:\Inetpub\vhosts\.com\httpdocs\site\key\index.php on line 36

config is correct *-*
 
ok realy thx Wizkidje and a last question xD can u make a simple login , change pass , ranking using the functions
WZ_ACCOUNT_ChangePassword , WZ_LeaderboardGet ?

i think is easy and fast for web coders and the functions already have. *-*
must important is login for player change pass *-*

can u make it for all ? *-*
 
ok realy thx Wizkidje and a last question xD can u make a simple login , change pass , ranking using the functions
WZ_ACCOUNT_ChangePassword , WZ_LeaderboardGet ?

i think is easy and fast for web coders and the functions already have. *-*
must important is login for player change pass *-*

can u make it for all ? *-*

I don't mind making that, but you'll have to post the stored procedures (right mouse > copy to > clipboard) or provide me with a test database as I have no idea how the database structure looks like.
 
I think all u need is here i think it is easy to u codes already done need make php call this *-*. i thin is hard make a login and logout *-* but try pls when u finish this codes i go make a nice template in flash + html5 for free too =)




WZ_ACCOUNT_ChangePassword

Code:
-- ----------------------------
-- Procedure structure for [WZ_ACCOUNT_ChangePassword]
-- ----------------------------

ALTER PROCEDURE [WZ_ACCOUNT_ChangePassword]
	@in_CustomerID int, 
	@in_NewPassword varchar(100)
AS
BEGIN
	SET NOCOUNT ON;

	-- update new password
	declare @MD5FromPwd varchar(100)
	exec FN_CreateMD5Password @in_NewPassword, @MD5FromPwd OUTPUT
	update Accounts set MD5Password=@MD5FromPwd where CustomerID=@in_CustomerID
	
	insert into DBG_PasswordResets (
		CustomerID,
		ResetDate,
		NewPassword
	) values (
		@in_CustomerID,
		GETDATE(),
		'' --@in_NewPassword Removed DO NOT store password as plain text ! ;/
	)

	select 0 as ResultCode
END


WZ_ACCOUNT_LOGIN

Code:
-- ----------------------------
-- Procedure structure for [WZ_ACCOUNT_LOGIN]
-- ----------------------------

ALTER PROCEDURE [dbo].[WZ_ACCOUNT_LOGIN]
	@in_IP varchar(100),
	@in_EMail varchar(100), 
	@in_Password varchar(100)
AS
BEGIN
	SET NOCOUNT ON;
	
	declare @CustomerID int
	declare @MD5Password varchar(100)
	declare @AccountStatus int = 0	-- this is Accounts.AccountStatus

	-- this call is always valid
	select 0 as ResultCode
	
	-- search for record with username
	SELECT 
		@CustomerID=CustomerID,
		@MD5Password=MD5Password,
		@AccountStatus=AccountStatus
	FROM Accounts
	WHERE email=@in_Email
	if (@@RowCount = 0) begin
		select
			1 as LoginResult,
			0 as CustomerID,
			0 as AccountStatus
		return
	end

	-- check MD5 password
	declare @MD5FromPwd varchar(100)
	exec FN_CreateMD5Password @in_Password, @MD5FromPwd OUTPUT
	if(@MD5Password <> @MD5FromPwd) begin
		select
			2 as LoginResult,
			0 as CustomerID,
			0 as AccountStatus
		return
	end
	
	-- check if deleted account because of refund
	if(@AccountStatus = 999) begin
		select
			3 as LoginResult,
			0 as CustomerID,
			999 as AccountStatus
		return
	end

-- check if ip banned
    declare @idccid int
    SELECT
        @idccid=cid
    FROM BannedIP 
    WHERE ip=@in_IP
    
    if (@@ROWCOUNT != 0) begin
        select
            3 as LoginResult,
            0 as CustomerID,
            998 as AccountStatus
        return
    end
	
	-- perform actual login
	exec WZ_ACCOUNT_LOGIN_EXEC @in_IP, @CustomerID
END

WZ_ACCOUNT_LOGIN_EXEC

Code:
-- ----------------------------
-- Procedure structure for [WZ_ACCOUNT_LOGIN_EXEC]
-- ----------------------------

ALTER PROCEDURE [WZ_ACCOUNT_LOGIN_EXEC]
	@in_IP varchar(100),
	@CustomerID int
AS
BEGIN
	SET NOCOUNT ON;
	
	--
	-- helper function that perform actual user login
	--
	
	declare @IsDeveloper int = 0
	declare @AccountStatus int
	declare @DateActiveUntil datetime
	declare @BanExpireDate datetime
	declare @lastgamedate datetime
	declare @GameServerId int
	select
		@AccountStatus=AccountStatus, 
		@IsDeveloper=IsDeveloper, 
		@DateActiveUntil=DateActiveUntil,
		@BanExpireDate=BanExpireDate,
		@GameServerId=GameServerId, 
		@lastgamedate=lastgamedate
		from UsersData where CustomerID=@CustomerID
	if(@@ROWCOUNT = 0) begin
		select
			5 as LoginResult,
			@CustomerID as CustomerID,
			0 as AccountStatus,
			0 as SessionID,
			0 as IsDeveloper
		return
	end

	-- check if account time expired
	if(GETDATE() > @DateActiveUntil) begin
		select
			4 as LoginResult,
			@CustomerID as CustomerID,
			300 as AccountStatus,	-- special 'TimeExpired' code
			0 as SessionID,
			0 as IsDeveloper
		return
	end 

	-- status equal to 201 means temporary ban
	if (@AccountStatus = 201) begin
		declare @BanExpireMin int = DATEDIFF(mi, GETDATE(), @BanExpireDate)
		if(@BanExpireMin > 0) begin
			select
				3 as LoginResult,
				@CustomerID as CustomerID,
				@AccountStatus as AccountStatus,
				@BanExpireMin as SessionID,
				0 as IsDeveloper
			return
		end
		else
		begin
			-- unban player
			set @AccountStatus = 100
			update dbo.UsersData set AccountStatus=@AccountStatus where CustomerID=@CustomerID
		end
	end

	if (@AccountStatus >= 200) begin
		select
			3 as LoginResult,
			@CustomerID as CustomerID,
			@AccountStatus as AccountStatus,
			0 as SessionID,
			0 as IsDeveloper
		return
	end
	
	-- check if game is still active or 90sec passed from last update (COPYPASTE_GAMECHECK, search for others)
	if(@GameServerId > 0 and DATEDIFF(second, @lastgamedate, GETDATE()) < 90) begin
		select
			0 as LoginResult,
			@CustomerID as CustomerID,
			70 as AccountStatus,	-- game still active code
			0 as SessionID,
			0 as IsDeveloper
		return
	end
	
	-- update session key/id
	declare @SessionKey varchar(50) = NEWID()
	declare @SessionID int = checksum(@SessionKey)
	if exists (SELECT CustomerID FROM LoginSessions WHERE CustomerID = @CustomerID)
	begin
		UPDATE LoginSessions SET 
			SessionKey=@SessionKey, 
			SessionID=@SessionID,
			LoginIP=@in_IP, 
			TimeLogged=GETDATE(), 
			TimeUpdated=GETDATE()
		WHERE CustomerID=@CustomerID
	end
	else
	begin
		INSERT INTO LoginSessions
			(CustomerID, SessionKey, SessionID, LoginIP, TimeLogged, TimeUpdated)
		VALUES 
			(@CustomerID, @SessionKey, @SessionID, @in_IP, GETDATE(), GETDATE())
	end

	-- update other tables
	UPDATE Accounts SET 
		lastlogindate=GETDATE(), 
		lastloginIP=@in_IP
	WHERE CustomerID=@CustomerID
	
	INSERT INTO Logins 
		(CustomerID, LoginTime, IP, LoginSource) 
	VALUES 
		(@CustomerID, GETDATE(), @in_IP, 0)

	-- return session info
	SELECT 
		0 as LoginResult,
		@CustomerID as CustomerID,
		@AccountStatus as AccountStatus,
		@SessionID as SessionID,
		@IsDeveloper as IsDeveloper
END

WZ_LeaderboardGet

Code:
-- ----------------------------
-- Procedure structure for [WZ_LeaderboardGet]
-- ----------------------------

ALTER PROCEDURE [WZ_LeaderboardGet]
	@in_Hardcore int,
	@in_Type int,
	@in_Page int
AS
BEGIN
	SET NOCOUNT ON;

	-- this call is always success
	SELECT 0 AS ResultCode

	DECLARE @rowsPerPage FLOAT = 100.0
	DECLARE @rowLimit INT = 2000;
	DECLARE @startPos INT = (@in_Page - 1) * @rowsPerPage

	IF @in_Type = 5 -- Heroes
	BEGIN
		SELECT TOP (@rowLimit) (@startPos + 1) AS StartPos, 
			CEILING(COUNT(*) / @rowsPerPage) AS PageCount
		FROM UsersChars
		WHERE Hardcore = @in_Hardcore AND Reputation >= 0		

		;WITH LeaderboardData AS
		(
			SELECT TOP (@rowLimit) Gamertag, Alive, Reputation AS Data,
				ROW_NUMBER() OVER
					(ORDER BY Reputation DESC) AS Pos
			FROM UsersChars
			WHERE Hardcore = @in_Hardcore AND Reputation >= 0
		)
		SELECT Gamertag, Alive, Data
		FROM LeaderboardData
		WHERE Pos > @startPos AND Pos <= @startPos + @rowsPerPage
	END
	ELSE IF @in_Type = 6 -- Villains
	BEGIN
		SELECT TOP (@rowLimit) (@startPos + 1) AS StartPos, 
			CEILING(COUNT(*) / @rowsPerPage) AS PageCount
		FROM UsersChars
		WHERE Hardcore = @in_Hardcore AND Reputation < 0	
	
		;WITH LeaderboardData AS
		(
			SELECT TOP (@rowLimit) Gamertag, Alive, Reputation AS Data,
				ROW_NUMBER() OVER
					(ORDER BY Reputation) AS Pos
			FROM UsersChars
			WHERE Hardcore = @in_Hardcore AND Reputation < 0
		)
		SELECT Gamertag, Alive, Data
		FROM LeaderboardData
		WHERE Pos > @startPos AND Pos <= @startPos + @rowsPerPage
	END
	ELSE
	BEGIN
		SELECT TOP (@rowLimit) (@startPos + 1) AS StartPos, 
			CEILING(COUNT(*) / @rowsPerPage) AS PageCount
		FROM UsersChars
		WHERE Hardcore = @in_Hardcore

		;WITH LeaderboardData AS
		(
			SELECT TOP (@rowLimit) Gamertag, Alive,
				CASE @in_Type
					WHEN 0 THEN XP
					WHEN 1 THEN TimePlayed
					WHEN 2 THEN Stat00 -- KilledZombies
					WHEN 3 THEN Stat01 -- KilledSurvivors
					WHEN 4 THEN Stat02 -- KilledBandits
					WHEN 5 THEN Reputation
					WHEN 6 THEN Reputation
					ELSE 0
				END AS Data,
				ROW_NUMBER() OVER
					(ORDER BY
						CASE WHEN @in_Type = 0 THEN XP END DESC,
						CASE WHEN @in_Type = 1 THEN TimePlayed END DESC,
						CASE WHEN @in_Type = 2 THEN Stat00 END DESC,
						CASE WHEN @in_Type = 3 THEN Stat01 END DESC,
						CASE WHEN @in_Type = 4 THEN Stat02 END DESC,
						CASE WHEN @in_Type = 5 THEN Reputation END DESC,
						CASE WHEN @in_Type = 6 THEN Reputation END) AS Pos
			FROM UsersChars
			WHERE Hardcore = @in_Hardcore
		)
		SELECT Gamertag, Alive, Data
		FROM LeaderboardData
		WHERE Pos > @startPos AND Pos <= @startPos + @rowsPerPage
	END
	
END


WZ_DB_GenerateLeaderboard

Code:
-- ----------------------------
-- Procedure structure for [WZ_DB_GenerateLeaderboard]
-- ----------------------------

ALTER PROCEDURE [WZ_DB_GenerateLeaderboard]
AS  
BEGIN  
	SET NOCOUNT ON;  
	
	-- reset table with zero seed
	delete from Leaderboard
	DBCC CHECKIDENT (Leaderboard, RESEED, 0)
	
	-- insert all ordered by honorpoints
	insert into Leaderboard (
			CustomerID, gamertag, HonorPoints,
			Kills, Deaths, Wins, Losses ,ShotsFired, ShotsHit, 
			TimePlayed,
			Rank,
			HavePremium)
		select
			LoginID.CustomerID, gamertag, HonorPoints,
			Stats.Kills, Stats.Deaths, Stats.Wins, Stats.Losses, Stats.ShotsFired, Stats.ShotsHits, 
			Stats.TimePlayed,
			-- get rank from table
			(select top(1) rank from DataRankPoints where LoginID.HonorPoints<DataRankPoints.HonorPoints order by HonorPoints asc),
			-- check if have premium
			(case when exists (select * from Inventory where ItemID=301004 and Inventory.CustomerID=LoginID.CustomerID and LeasedUntil>GETDATE()) 
				then 1
				else 0
			end)
		from LoginID
		join Stats on Stats.CustomerID=LoginID.CustomerID
		where AccountStatus=101
		order by LoginID.HonorPoints desc

END

WZ_ClanSetMemberRank

Code:
-- ----------------------------
-- Procedure structure for [WZ_ClanSetMemberRank]
-- ----------------------------

ALTER PROCEDURE [WZ_ClanSetMemberRank]
	@in_CharID int,
	@in_MemberID int,
	@in_Rank int
AS
BEGIN
	SET NOCOUNT ON;
	
-- sanity checks
	if(@in_CharID = @in_MemberID) begin
		select 6 as 'ResultCode', 'can not set own rank' as 'ResultMsg'
		return
	end

	-- clan id valudation of caller
	declare @ClanID int = 0
	declare @ClanRank int
	declare @Gamertag nvarchar(64)
	select @ClanID=ClanID, @ClanRank=ClanRank, @Gamertag=Gamertag from UsersChars where CharID=@in_CharID
	if(@ClanID = 0) begin
		select 6 as ResultCode, 'no clan' as ResultMsg
		return
	end
	
	-- clan id validation of member
	declare @MemberClanID int = 0
	declare @MemberGamerTag nvarchar(64)
	declare @MemberClanRank int
	declare @MemberCustomerID int
	select @MemberClanID=ClanID, @MemberClanRank=ClanRank, @MemberGamerTag=GamerTag, @MemberCustomerID=CustomerID from UsersChars where CharID=@in_MemberID
	if(@MemberClanID <> @ClanID) begin
		select 6 as ResultCode, 'member in wrong clan' as ResultMsg
		return
	end
	
-- validate that we can change rank

	-- only leader and officers can change ranks
	if(@ClanRank > 1) begin
		select 23 as ResultCode, 'no permission' as ResultMsg
		return
	end

	-- cant change higher rank
	if(@ClanRank > 0 and @ClanRank >= @MemberClanRank) begin
		select 6 as ResultCode, 'cant change highter rank' as ResultMsg
		return
	end
	
	if(@ClanRank > 0 and @ClanRank >= @in_Rank) begin
		select 6 as ResultCode, 'cant set same rank' as ResultMsg
		return
	end
	
-- code for changing clan ownership, owner becomes officer
	if(@ClanRank = 0 and @in_Rank = 0) begin
		update UsersChars set ClanRank=1 where CharID=@in_CharID
		update ClanData set OwnerCharID=@in_MemberID, OwnerCustomerID=@MemberCustomerID where ClanID=@ClanID
	end
	
-- update target member
	update UsersChars set ClanRank=@in_Rank where CharID=@in_MemberID
	
-- generate clan set rank event
	insert into ClanEvents (
		ClanID,
		EventDate,
		EventType,
		EventRank,
		Var1,
		Var2,
		Var3,
		Text1,
		Text2
	) values (
		@ClanID,
		GETDATE(),
		3, -- CLANEVENT_SetRank
		99, -- Visible to all
		@in_CharID,
		@in_MemberID,
		@in_Rank,
		@Gamertag,
		@MemberGamertag
	)
	
	-- TODO: send message to player about rank change
	
	-- success
	select 0 as ResultCode
END
 
Back