From f4142c0529400b1ac62645aa69cb3b816f1764e5 Mon Sep 17 00:00:00 2001 From: nolanwhy Date: Sun, 5 Feb 2023 13:36:56 +0100 Subject: [PATCH] Update register.php --- register.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/register.php b/register.php index f89bc83..0294eba 100644 --- a/register.php +++ b/register.php @@ -10,6 +10,7 @@ require_once 'core/config.php'; $getitstarted = new PartyStarter; $getitstarted->header(); +$usernamespecialchar = false; $passwordconfirmiswrong = false; $passwordistooshort = false; $user = new User($con, 0); @@ -24,6 +25,12 @@ if(isset($_POST['submit'])) { } '; $user = new User($con, $user->getID($con, $username)); + if(preg_match('/^[a-zA-Z0-9]+$/', $username) == 0) { + $usernamespecialchar = true; + } else { + $usernamespecialchar = false; + } + if ($password == $passwordconfirm) { $passwordconfirmiswrong = false; } else { @@ -35,7 +42,7 @@ if(isset($_POST['submit'])) { } else { $passwordistooshort = false; } - if ($passwordistooshort == false && $passwordconfirmiswrong == false) { + if ($passwordistooshort == false && $passwordconfirmiswrong == false && $usernamespecialchar == false) { $password = password_hash($password, PASSWORD_BCRYPT); $query = $con->prepare('SELECT COUNT(*) FROM users WHERE username=:username'); $query->bindParam(':username', $username); @@ -82,7 +89,7 @@ $thefunfact = json_decode($result);

Registration

- " type="text" placeholder="Your username" id="inputSmall" for="inputValid" name="username"> Username is already taken.
'; } ?> + " type="text" placeholder="Your username" id="inputSmall" for="inputValid" name="username"> Username is already taken.'; } elseif($usernamespecialchar == true) { echo '
Special characters are not allowed.
'; } ?> " type="password" placeholder="Your password (Minmum 8 characters)" id="inputSmall" name="pass"> Password Confirmation field is invalid.'; } else if ($passwordistooshort == true) { echo '
Password is too short. (8 Characters minmum)
'; } ?>