verify(), 'lostpassword' => lostpassword(), 'changepassword' => changepassword(), default => register() }; /** * Register a new account. */ function register() { global $controlrow; if (isset($_POST["submit"])) { $form = validate($_POST, [ 'username' => ['length:3-18', 'alpha-spaces', 'unique:users,username'], 'email' => ['email', 'unique:users,email'], 'confirm_email' => ['confirm'], 'password' => ['length:6-255'], 'confirm_password' => ['confirm'], 'charclass' => ['in:1,2,3'] ]); if (!$form['valid']) { $err = ul_from_validate_errors($form['errors']); $page = "The following error(s) occurred when your account was being made:
$err
Please go back and try again."; } else { $form = $form['data']; $password = password_hash($form['password'], PASSWORD_ARGON2ID); $token = ($controlrow['verifyemail'] == true) ? token(8) : 'g2g'; db()->query('INSERT INTO users (verify, username, password, email, charclass) VALUES (?, ?, ?, ?, ?)', [ $token, $form['username'], $password, $form['email'], $form['charclass'] ]); if ($controlrow['verifyemail'] == true) { if (sendregmail($form['email'], $token)) { $page = "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 { $page = "Your account was created successfully.

However, there was a problem sending your verification email. Please check with the game administrator to help resolve this problem."; } } else { $page = "Your account was created succesfully.

You may now continue to the Login Page and continue playing ".$controlrow["gamename"]."!"; } } } else { if ($controlrow["verifyemail"] == true) { $controlrow["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."; } else { $controlrow["verifytext"] = ""; } $page = parsetemplate(gettemplate("register"), $controlrow); } display($page, "Register", false, false, false); } function verify() { if (isset($_POST["submit"])) { $u = trim($_POST['username'] ?? ''); $e = trim($_POST['email'] ?? ''); $t = trim($_POST['token'] ?? ''); $query = db()->query('SELECT id FROM users WHERE username=? AND email=? AND verify=? LIMIT 1;', [$u, $e, $t]); if ($query === false) exit('Verification failed. Go back, double-check your details, and try again.'); db()->query("UPDATE users SET verify='g2g' WHERE username=?;", [$u]); display("Your account was verified successfully.

You may now continue to the Login Page and start playing the game.

Thanks for playing!","Verify Email",false,false,false); } $topnav = "\"Log\"Register\"\"Help\""; display(gettemplate("verify"), "Verify Email", false, false, false); } function lostpassword() { if (isset($_POST["submit"])) { $e = trim($_POST['email'] ?? ''); if (!db()->exists('users', 'email', $e)) exit("No account with that email address."); $newpass = token(16); $hashed = password_hash($newpass, PASSWORD_ARGON2ID); db()->query('UPDATE users SET password=? WHERE email=?;', [$hashed, $e]); if (sendpassemail($e, $newpass)) { display("Your new password was emailed to the address you provided.

Once you receive it, you may Log In and continue playing.

Thank you.","Lost Password",false,false,false); } else { display("There was an error sending your new password.

Please check with the game administrator for more information.

We apologize for the inconvience.","Lost Password",false,false,false); } } $topnav = "\"Log\"Register\"\"Help\""; display(gettemplate("lostpassword"), "Lost Password", false, false, false); } function changepassword() { if (isset($_POST["submit"])) { $u = trim($_POST['username'] ?? ''); $p = $_POST['password'] ?? ''; $np = $_POST['new_password'] ?? ''; $np2 = $_POST['new_password2'] ?? ''; $user = db()->query("SELECT password FROM users WHERE username=? LIMIT 1;", [$u]); $user = $user->fetchArray(SQLITE3_ASSOC); if ($user === false) exit("No account with that username."); if (!password_verify($p, $user['password'])) exit("The old password you provided was incorrect."); if (empty($np) || strlen($np) < 6) { $errors[] = 'New password is required and must be at least 6 characters long.'; } if ($np2 !== $np) { $errors[] = 'Verify New Password must match.'; } $realnewpass = password_hash($np, PASSWORD_ARGON2ID); db()->query('UPDATE users SET password=? WHERE username=?;', [$realnewpass, $u]); set_cookie('dkgame', '', -3600); display("Your password was changed successfully.

You have been logged out of the game to avoid errors.

Please log back in to continue playing.","Change Password",false,false,false); } $topnav = "\"Log\"Register\"\"Help\""; display(gettemplate("changepassword"), "Change Password", false, false, false); } function sendpassemail($emailaddress, $password) { global $controlrow; extract($controlrow); $email = <<'; $rp = $controlrow["adminemail"]; $org = '$gameurl'; $mailer = 'PHP'; $head = ''; $head .= "Content-Type: text/plain \r\n"; $head .= "Date: ". date('r'). " \r\n"; $head .= "Return-Path: $rp \r\n"; $head .= "From: $from \r\n"; $head .= "Sender: $from \r\n"; $head .= "Reply-To: $from \r\n"; $head .= "Organization: $org \r\n"; $head .= "X-Sender: $from \r\n"; $head .= "X-Priority: 3 \r\n"; $head .= "X-Mailer: $mailer \r\n"; $body = str_replace("\r\n", "\n", $body); $body = str_replace("\n", "\r\n", $body); return mail($to, $title, $body, $head); }