From 04d30cfe16e11140c8efb22afd61f2386c35cd87 Mon Sep 17 00:00:00 2001
From: cflip <36554078+cflip@users.noreply.github.com>
Date: Tue, 20 Jul 2021 17:25:03 -0600
Subject: Handle input validation in abstract Form class
---
register.php | 116 ++++++++++++++++++++---------------------------------------
1 file changed, 38 insertions(+), 78 deletions(-)
(limited to 'register.php')
diff --git a/register.php b/register.php
index 5128f10..34e43a0 100755
--- a/register.php
+++ b/register.php
@@ -1,78 +1,38 @@
-
-
-
-
- Register an account - cflip.net forum
-
-
-
-
- Register an account
-
-
- 30) {
- $errors[] = "Your username must be 30 characters or less.";
- }
-
- if (username_exists($user_name) !== false) {
- $errors[] = "The username '" . $user_name . "' has already been taken by another user.";
- }
- }
-
- if (empty($_POST['user_pass'])) {
- $errors[] = "You must provide a password.";
- } else {
- $user_pass = $_POST['user_pass'];
- $pass_check = $_POST['user_pass_check'];
-
- if (preg_match("/^[a-zA-Z0-9\W]*$/", $user_pass) === false) {
- $errors[] = "Password contains invalid characters!";
- }
-
- if ($user_pass !== $pass_check) {
- $errors[] = "The two passwords do not match.";
- }
- }
-
- if (!empty($errors)) {
- $errstr = 'Please check the following problems: ';
- foreach ($errors as $err) {
- $errstr .= '- ' . $err . '
';
- }
- $errstr .= '
';
- trigger_error($errstr);
- } else {
- $pass_hash = password_hash($user_pass, PASSWORD_DEFAULT);
- User::register($user_name, $pass_hash);
- echo 'Account successfully registered! You can now sign in
';
- }
-}
-?>
-
-
+
+
+
+
+ Register an account - cflip.net forum
+
+
+
+
+ Register an account
+
+
+validate_username($_POST['user_pass']);
+ $password = $form->validate_password($_POST['user_pass'], $_POST['user_pass_check']);
+
+ $form->on_success(function () use ($username, $password) {
+ User::register($username, $password);
+ echo 'Account successfully registered! You can now sign in
';
+ });
+}
+?>
+
+
--
cgit v1.2.3