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
';
}
}
?>