Skip to content

Instantly share code, notes, and snippets.

@jtsternberg
Forked from bradp/ugh.php
Last active June 9, 2016 17:20
Show Gist options
  • Save jtsternberg/ff670e4dfc250aaf3b598490a9f1dbb3 to your computer and use it in GitHub Desktop.
Save jtsternberg/ff670e4dfc250aaf3b598490a9f1dbb3 to your computer and use it in GitHub Desktop.
dont_do_this
<?php
//dis like the best code ever
function register() {
$msg = '';
if ( empty( $_POST ) ) {
return 'Fill out the form, dummy!';
}
if (! $_POST['user_name']) {
return 'Empty Username';
}
if (! $_POST['user_password_new']) {
return 'Empty Password';
}
if ($_POST['user_name']) {
if ($_POST['user_password_new']) {
if ($_POST['user_password_new'] === $_POST['user_password_repeat']) {
if (strlen($_POST['user_password_new']) > 5) {
if (strlen($_POST['user_name']) < 65 && strlen($_POST['user_name']) > 1) {
if (preg_match('/^[a-z\d]{2,64}$/i', $_POST['user_name'])) {
$user = read_user($_POST['user_name']);
if (!isset($user['user_name'])) {
if ($_POST['user_email']) {
if (strlen($_POST['user_email']) < 65) {
if (filter_var($_POST['user_email'], FILTER_VALIDATE_EMAIL)) {
create_user();
$_SESSION['msg'] = 'You are now registered so please login';
header('Location: ' . $_SERVER['PHP_SELF']);
exit();
} else $msg = 'You must provide a valid email address';
} else $msg = 'Email must be less than 64 characters';
} else $msg = 'Email cannot be empty';
} else $msg = 'Username already exists';
} else $msg = 'Username must be only a-z, A-Z, 0-9';
}
} else $msg = 'Password must be at least 6 characters';
} else $msg = 'Passwords do not match';
} else $msg = 'Empty Password';
} else $msg = 'Empty Username';
$_SESSION['msg'] = $msg;
}
$_SESSION['msg'] = 'You are now registered so please login';
header('Location: ' . $_SERVER['PHP_SELF']);
exit();
return register_form();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment