<?php
if($__TOKEN = "hardcodeshitbykernstudios"){
echo '<h2 class="bg-h2-1 bot">SignUp</h2>';
	if(isset($_POST['submit'])){
		if(empty($_POST['username']) || empty($_POST['password']) || empty($_POST['email']) || empty($_POST['secpassword'])){
			exit();
		}
		$username = mssql_escape_string($_POST['username']);
		$password = mssql_escape_string($_POST['password']);
		$email = mssql_escape_string($_POST['email']);
		
		if($password == $_POST['secpassword']){
			$conn = sqlsrv_connect($__CONFIG['SQLHost'], array("Database"=>$__CONFIG['SQLDB'], "UID"=>$__CONFIG['SQLUID'], "PWD"=>$__CONFIG['SQLPWD']));
			if(!$conn){
				echo print_r(sqlsrv_errors(), true);
			}else{
				if(filter_var($email, FILTER_VALIDATE_EMAIL)){
					$checkAccount = sqlsrv_query($conn, "SELECT * FROM tAccounts WHERE sUsername = ?;", array($username), array( "Scrollable" => SQLSRV_CURSOR_KEYSET ));
										if(sqlsrv_num_rows($checkAccount) == 0){
						$insertAccount = sqlsrv_query($conn, "INSERT INTO tAccounts (sUsername, sUserPass, sUserPassSalt, sIP, sEmail, nAuthID) VALUES (?, ?, ?, ?, ?, 3);", array($username, md5($password), generateRandomString(8), getRemoteIP(), $email));
						if(!$insertAccount)
						{
							showMessage('error', 'Ooops where are my carrots ? '.print_r(sqlsrv_errors(), true));
						}else{
							if($insertAccount){
								showMessage('success', 'Welcome to the world of Charisma Gaming. '.$username.'<br>Account has been successfully created!');
							}else{
								showMessage('error', 'Ooops where are my carrots ? '.print_r(sqlsrv_errors(), true));
							}
						}
					}else{
						showMessage('error', 'Account ID already exists!');
					}
				}else{
					showMessage('error', 'You entered a wrong email! The email need at least one @(at) and one .(dot)!');
				}
			}
		}else{
			showMessage('error', 'Password does not match!');
		}
	}else{
		echo '<center><form method="post" style="display: block;"><input type="text" name="username" placeholder="Username" maxlength="50" required><br></br><input type="password" name="password" placeholder="Password" required><br><br><input type="password" name="secpassword" placeholder="Repeat password" required><br><br><input type="text" name="email" placeholder="E-mail" required><br><br><input type="submit" name="submit" value="Submit" class="myButton"></form></center>';
	}
}
?>