display('login'); } function index_post() { global $renderer; global $router; // TODO: change the password encryption method $query = doquery("SELECT * FROM {{table}} WHERE username='".$_POST["username"]."' AND password='".md5($_POST["password"])."' LIMIT 1", "users"); if (mysqli_num_rows($query) != 1) { $renderer->simple("Connexion error", "Invalid username or password. Please go back and try again."); } $row = mysqli_fetch_array($query); if (isset($_POST["rememberme"])) { $expiretime = time()+31536000; $rememberme = 1; } else { $expiretime = 0; $rememberme = 0; } $cookie = $row["id"] . " " . $row["username"] . " " . md5($row["password"] . "--" . $dbsettings["secretword"]) . " " . $rememberme; setcookie("dkgame", $cookie, $expiretime, "/", "", 0); $router->redirect("/"); } function register() { // Register a new account. global $controlrow; global $renderer; if ($controlrow["verifyemail"] == 1) { $renderer->prepare("verifytext", "A verification code will be sent to the address above, and you will not be able to log in without first entering the code. Please be sure to enter your correct email address."); } $renderer->prepare("class1name", $controlrow["class1name"]); $renderer->prepare("class2name", $controlrow["class2name"]); $renderer->prepare("class3name", $controlrow["class3name"]); $renderer->prepare("diff1name", $controlrow["diff1name"]); $renderer->prepare("diff2name", $controlrow["diff2name"]); $renderer->prepare("diff3name", $controlrow["diff3name"]); $renderer->display("register"); } function register_post() { global $renderer; global $messages; global $router; global $controlrow; global $postData; $postData->addField("Username", ["required", "alphanumeric", "unique"], "username", ["field"=>"username", "table"=>"users"]); $postData->addField("Character Name", ["required", "alphanumeric", "unique"], "charname", ["field"=>"charname", "table"=>"users"]); $postData->addFields("Email", ["required", "mail", "equals", "unique"], ["email1", "email2"], ["field"=>"email", "table"=>"users"]); $postData->addFields("Password", ["required", "alphanumeric", "equals"], ["password1", "password2"]); $postData->addField("Difficulty", [], "difficulty"); $postData->addField("Character Class", [], "charclass"); if ($postData->validate() == false) { $renderer->addPostFields(["username", "charname", "email1", "charclass", "difficulty"]); $renderer->prepare("class1name", $controlrow["class1name"]); $renderer->prepare("class2name", $controlrow["class2name"]); $renderer->prepare("class3name", $controlrow["class3name"]); $renderer->prepare("diff1name", $controlrow["diff1name"]); $renderer->prepare("diff2name", $controlrow["diff2name"]); $renderer->prepare("diff3name", $controlrow["diff3name"]); $messages->putList("danger", "The following error(s) occurred when your account was being made:", $postData->errors); $renderer->display("register"); } $username = $postData->getField("username"); $email = $postData->getField("email1"); $charname = $postData->getField("charname"); $charclass = $postData->getField("charclass"); $difficulty = $postData->getField("difficulty"); $password = md5($password1); $verifycode = ($controlrow["verifyemail"] == 1) ? substr(str_shuffle(str_repeat('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-', 8)), 0, 8) : '1'; $query = doquery("INSERT INTO {{table}} SET regdate=NOW(),verify='$verifycode',username='$username',password='$password',email='$email',charname='$charname',charclass='$charclass',difficulty='$difficulty'", "users") or die(mysql_error()); if ($controlrow["verifyemail"] == 1) { if (__sendregmail($email, $verifycode) == true) { $messages->put("success", "Your account was created successfully.

You should receive an Account Verification email shortly. You will need the verification code contained in that email before you are allowed to log in. Once you have received the email, please visit the Verification Page to enter your code and start playing."); } else { $messages->put("danger", "Your account was created succesfully.

However, there was a problem sending your verification email. Please check with the game administrator to help resolve this problem."); } } else { $messages->put("success", "Your account was created succesfully.

You may now continue to the Login Page and start playing ".$controlrow["gamename"]."!"); } $router->redirect(); } function __sendregmail($emailaddress, $vercode) { $controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control"); $controlrow = mysqli_fetch_array($controlquery); extract($controlrow); $verurl = $gameurl . "?do=verify"; $email = <<