diff --git a/var/www/signup.php b/var/www/signup.php new file mode 100644 index 0000000..887d501 --- /dev/null +++ b/var/www/signup.php @@ -0,0 +1,63 @@ +<>,|=_+¬-]/',$_POST['signup_username']) && (preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/',$_POST['signup_password'])){ + // Need to first check if a user with the desired username already esists + $db_check_statement = $db_connection->prepare("SELECT COUNT(*) FROM login WHERE username = '".$_POST["signup_username"]."'"); + $db_check_statement->execute(); + $db_check_statement->setFetchMode(PDO::FETCH_ASSOC); + $db_check_returned = $db_statement->fetchAll(); + $existingUsers = $db_check_returned[0]['COUNT(*)']; + if($existingUsers == 0){ + $db_connection->exec("INSERT INTO login (username, pword) VALUES ('".$_POST["signup_username"]."','".$_POST["signup_password"]."')"); + $_SESSION["loginError"] = "Your account has been created and can now login"; + unset($_SESSION['signupError']); + header('Location: /login.php'); + }else{$_SESSION["signupError"] = "Another user with that username already exists, please choose another name";} + }else{$_SESSION["signupError"] = "Special characters are not allowed";} + }else{$_SESSION["signupError"] = "Password must be at least 4 characters and at most 25 characters";} + }else{$_SESSION["signupError"] = "Username must be at least 4 characters and at most 25 characters";} + }else{ + // If user submitted form wihout actually filling it out completely, send user an error message + if(!empty($_POST)){ + $_SESSION["signupError"] = "Username and Password are required, please try again"; + } + } + }catch(PDOException $e){echo "PDOException: ".$e->getMessage(); + }catch(Exception $e){echo "Exception: ".$e->getMessage(); + } +?> + + + +
+