diff options
Diffstat (limited to 'register.php')
-rwxr-xr-x[-rw-r--r--] | register.php | 157 |
1 files changed, 78 insertions, 79 deletions
diff --git a/register.php b/register.php index 9eb3347..5128f10 100644..100755 --- a/register.php +++ b/register.php @@ -1,79 +1,78 @@ -<?php session_start() ?> -<!DOCTYPE html> -<html lang="en"> -<head> - <title>Register an account - cflip.net forum</title> - <link rel="stylesheet" href="styles/style.css"> -</head> -<body> -<?php include './includes/templates/header.php' ?> -<h2>Register an account</h2> -<form action="register.php" method="post"> - <label for="user_name">Username: </label><br> - <input type="text" name="user_name"><br> - <label for="user_pass">Password: </label><br> - <input type="password" name="user_pass"><br> - <label for="user_pass_check">Re-enter password: </label><br> - <input type="password" name="user_pass_check"><br> - <input type="submit" name="submit"> -</form> -<br> - -<?php -include_once './includes/model/User.php'; -include_once './includes/error.php'; - -if ($_SERVER['REQUEST_METHOD'] == 'POST') { - $errors = array(); - - $user_name = ""; - $user_pass = ""; - - if (empty($_POST['user_name'])) { - $errors[] = "You must provide a username."; - } else { - $user_name = $_POST['user_name']; - if (!preg_match("/^[a-zA-Z0-9_]*$/", $user_name)) { - $errors[] = "Username can only contain letters, numbers and underscores."; - } - - if (strlen($user_name) > 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: <ul>'; - foreach ($errors as $err) { - $errstr .= '<li>' . $err . '</li>'; - } - $errstr .= '</ul>'; - trigger_error($errstr); - } else { - $pass_hash = password_hash($user_pass, PASSWORD_DEFAULT); - User::register($user_name, $pass_hash); - echo '<p class="success">Account successfully registered! You can now <a href="signin.php">sign in</a></p>'; - } -} -?> -</body> -</html> +<?php session_start() ?>
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <title>Register an account - cflip.net forum</title>
+<?php include_once 'includes/templates/head.php'; ?>
+</head>
+<body>
+<?php include './includes/templates/header.php' ?>
+ <h2>Register an account</h2>
+ <form action="register.php" method="post">
+ <label for="user_name">Username: </label><br>
+ <input type="text" name="user_name"><br>
+ <label for="user_pass">Password: </label><br>
+ <input type="password" name="user_pass"><br>
+ <label for="user_pass_check">Re-enter password: </label><br>
+ <input type="password" name="user_pass_check"><br>
+ <input type="submit" name="submit">
+ </form>
+ <br>
+<?php
+include_once './includes/model/User.php';
+include_once './includes/error.php';
+
+if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+ $errors = array();
+
+ $user_name = "";
+ $user_pass = "";
+
+ if (empty($_POST['user_name'])) {
+ $errors[] = "You must provide a username.";
+ } else {
+ $user_name = $_POST['user_name'];
+ if (!preg_match("/^[a-zA-Z0-9_]*$/", $user_name)) {
+ $errors[] = "Username can only contain letters, numbers and underscores.";
+ }
+
+ if (strlen($user_name) > 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: <ul>';
+ foreach ($errors as $err) {
+ $errstr .= '<li>' . $err . '</li>';
+ }
+ $errstr .= '</ul>';
+ trigger_error($errstr);
+ } else {
+ $pass_hash = password_hash($user_pass, PASSWORD_DEFAULT);
+ User::register($user_name, $pass_hash);
+ echo '<p class="success">Account successfully registered! You can now <a href="signin.php">sign in</a></p>';
+ }
+}
+?>
+</body>
+</html>
|