diff --git a/public/index.php b/public/index.php index 7650919..df9b5cf 100644 --- a/public/index.php +++ b/public/index.php @@ -115,7 +115,7 @@ function dotown() while ($onlinerow = $onlinequery->fetchArray(SQLITE3_ASSOC)) { $online_count++; - $online_rows[] = "".$onlinerow["username"]."" . ", "; + $online_rows[] = "".$onlinerow["username"].""; } $townrow["whosonline"] = "
Who's Online | ||||||||||||||||||||
\n";
diff --git a/public/install.php b/public/install.php
index d4347dc..e2ef74b 100644
--- a/public/install.php
+++ b/public/install.php
@@ -621,7 +621,7 @@ function second()
`username` TEXT NOT NULL,
`password` TEXT NOT NULL,
`email` TEXT NOT NULL,
- `verify` INTEGER NOT NULL default 0,
+ `verify` TEXT NOT NULL default '',
`regdate` datetime NOT NULL default CURRENT_TIMESTAMP,
`onlinetime` datetime NOT NULL default CURRENT_TIMESTAMP,
`authlevel` INTEGER NOT NULL default 0,
diff --git a/public/login.php b/public/login.php
index b19be3e..c57fd39 100644
--- a/public/login.php
+++ b/public/login.php
@@ -2,10 +2,7 @@
// login.php :: Handles logins and cookies.
-if (!file_exists('../.installed')) {
- header('Location: install.php');
- exit;
-}
+if (!file_exists('../.installed')) redirect('install.php');
require_once '../src/lib.php';
diff --git a/public/users.php b/public/users.php
index 07d9f28..7a89a48 100644
--- a/public/users.php
+++ b/public/users.php
@@ -1,239 +1,252 @@
- verify(),
+ 'lostpassword' => lostpassword(),
+ 'changepassword' => changepassword(),
+ default => register()
+};
- $controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control");
- $controlrow = mysql_fetch_array($controlquery);
+/**
+ * Register a new account.
+ */
+function register()
+{
+ global $controlrow;
if (isset($_POST["submit"])) {
+ $u = trim($_POST['username'] ?? '');
+ $e = trim($_POST['email1'] ?? '');
+ $e2 = trim($_POST['email2'] ?? '');
+ $p = $_POST['password1'] ?? '';
+ $p2 = $_POST['password2'] ?? '';
- extract($_POST);
-
- $errors = 0; $errorlist = "";
+ $errors = [];
// Process username.
- if ($username == "") { $errors++; $errorlist .= "Username field is required. "; } - if (preg_match("/[^A-z0-9_\-]/", $username)==1) { $errors++; $errorlist .= "Username must be alphanumeric. "; } // Thanks to "Carlos Pires" from php.net! - $usernamequery = doquery("SELECT username FROM {{table}} WHERE username='$username' LIMIT 1","users"); - if (mysql_num_rows($usernamequery) > 0) { $errors++; $errorlist .= "Username already taken - unique username required. "; } + if (empty($u) || strlen($u) < 3 || strlen($u) > 18 || !ctype_alnum(str_replace(' ', '', $u))) { + $errors[] = 'Username is required and must be between 3 and 18 characters long and contain only + alphanumeric characters and spaces.'; + } + + if (db()->exists('users', 'username', $u)) { + $errors[] = 'Username already taken. Try another.'; + } // Process email address. - if ($email1 == "" || $email2 == "") { $errors++; $errorlist .= "Email fields are required. "; } - if ($email1 != $email2) { $errors++; $errorlist .= "Emails don't match. "; } - if (! is_email($email1)) { $errors++; $errorlist .= "Email isn't valid. "; } - $emailquery = doquery("SELECT email FROM {{table}} WHERE email='$email1' LIMIT 1","users"); - if (mysql_num_rows($emailquery) > 0) { $errors++; $errorlist .= "Email already taken - unique email address required. "; } + if (empty($e) || strlen($e) > 255 || !filter_var($e, FILTER_VALIDATE_EMAIL)) { + $errors[] = 'Email is required must be a valid email address.'; + } + + if ($e !== $e2) { + $errors[] = 'Verify Email must match.'; + } + + if (db()->exists('users', 'email', $e)) { + $errors[] = 'Email already taken. Forgot your password?'; + } // Process password. - if (trim($password1) == "") { $errors++; $errorlist .= "Password field is required. "; } - if (preg_match("/[^A-z0-9_\-]/", $password1)==1) { $errors++; $errorlist .= "Password must be alphanumeric. "; } // Thanks to "Carlos Pires" from php.net! - if ($password1 != $password2) { $errors++; $errorlist .= "Passwords don't match. "; } - $password = md5($password1); + if (empty($p) || strlen($p) < 6) { + $errors[] = 'Password is required and must be at least 6 characters long.'; + } - if ($errors == 0) { + if ($p2 !== $p) { + $errors[] = 'Verify Password must match.'; + } - if ($controlrow["verifyemail"] == 1) { - $verifycode = ""; - for ($i=0; $i<8; $i++) { - $verifycode .= chr(rand(65,90)); - } - } else { - $verifycode='1'; - } + $password = password_hash($p, PASSWORD_ARGON2ID); - $query = doquery("INSERT INTO {{table}} SET id='',regdate=NOW(),verify='$verifycode',username='$username',password='$password',email='$email1',charclass='$charclass'", "users") or die(mysql_error()); + if (count($errors) !== 0) { + $err = "
$err Please go back and try again."; + } else { + $token = ($controlrow['verifyemail'] == true) ? token(8) : 'g2g'; + db()->query('INSERT INTO users (verify, username, password, email, charclass) VALUES (?, ?, ?, ?, ?)', [ + $token, $u, $password, $e, $_POST['charclass'] ?? 1 + ]); - if ($controlrow["verifyemail"] == 1) { - if (sendregmail($email1, $verifycode) == true) { + if ($controlrow['verifyemail'] == true) { + if (sendregmail($e, $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 { - - $page = "The following error(s) occurred when your account was being made: $errorlist Please go back and try again."; - - } - + } else { + $page = "Your account was created succesfully. You may now continue to the Login Page and continue playing ".$controlrow["gamename"]."!"; + } + } } else { - - $page = gettemplate("register"); - if ($controlrow["verifyemail"] == 1) { + 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($page, $controlrow); + $page = parsetemplate(gettemplate("register"), $controlrow); } $topnav = " ![]() ![]() ![]() You may now continue to the Login Page and start playing the game. Thanks for playing!","Verify Email",false,false,false); } - $page = gettemplate("verify"); - $topnav = " ![]() ![]() ![]() ![]() ![]() ![]() 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); } - die(); } - $page = gettemplate("lostpassword"); + $topnav = " ![]() ![]() ![]() You have been logged out of the game to avoid cookie errors. Please log back in to continue playing.","Change Password",false,false,false); - die(); - } - $page = gettemplate("changepassword"); - $topnav = " ![]() ![]() ![]() You have been logged out of the game to avoid errors. Please log back in to continue playing.","Change Password",false,false,false); + } + + $topnav = " ![]() ![]() ![]()
|