Register an account








30) { $errors[] = "Your username must be 30 characters or less."; } if (username_exists($dbc, $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)) { echo 'Please check the following problems: '; } else { $sql = "INSERT INTO users(user_name, user_pass, user_date) VALUES(?, ?, NOW());"; $stmt = mysqli_stmt_init($dbc); if (!mysqli_stmt_prepare($stmt, $sql)) { die('Could not create account due to internal error: ' . mysqli_error($dbc)); } $pass_hash = password_hash($user_pass, PASSWORD_DEFAULT); mysqli_stmt_bind_param($stmt, "ss", $user_name, $pass_hash); mysqli_stmt_execute($stmt); mysqli_stmt_close($stmt); echo 'Account successfully registered! You can now sign in'; } } ?>