Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Hola
- */
- $connection = [
- 'host' => '',
- 'username' => '',
- 'password' => '',
- 'database' => ''
- ];
- // HOW CAN I RESIST YOU
- list($host, $username, $password, $database) = $connection;
- $mysqli = new mysqli($host, $username, $password, $database);
- if ($mysqli->error) {
- exit; // how do I handle this
- }
- /*
- 700 = user taken
- 710 = 5 accounts on email
- 600 = custom ban message
- */
- $get_val = function ($val) use ($mysqli)
- {
- if (! isset($_POST[$val])) {
- return '';
- }
- $val = $_POST[$val];
- $val = trim($val);
- return $val;
- };
- $username = $get_val('n');
- $password = $get_val('p');
- $email = $get_val('email');
- if ($_SERVER['HTTP_REFERER'] === 'http://clubpenguin.io/penguin/chat.swf') {
- exit('e=600');
- }
- if ( ! ($username && $password && $email)) { // empty?
- exit('e=28');
- }
- if (! preg_match('/^[a-z0-9]{3-14}$/', $username)) {
- exit('e=600');
- }
- if (! filter_var($email, FILTER_VALIDATE_EMAIL)) {
- exit('e=28');
- }
- if (mb_strlen($password, 'utf-8') < 3) {
- exit('e=28'); // too short
- }
- $user_exists = "SELECT COUNT(*) AS size FROM users WHERE username = '%s'";
- $user_exists = sprintf($user_exists, $mysqli->real_escape($username));
- $user_exists = $mysqli->query($user_exists);
- if (! $user_exists) {
- // query failed
- exit('e=28');
- }
- $user_exists = $mysqli->fetch_row();
- $user_exists = !! $user_exists[0];
- if ($user_exists) {
- exit('e=28');
- }
- $email_exists = "SELECT COUNT(*) AS size FROM users WHERE username = '%s'";
- $email_exists = sprintf($email_exists, $mysqli->real_escape($email));
- $email_exists = $mysqli->query($email_exists);
- if (! $email_exists) {
- // query failed
- exit('e=28');
- }
- $email_exists = $mysqli->fetch_row();
- $email_exists = !! $email_exists[0];
- if ($email_exists) {
- exit('e=29');
- }
- $password = strtoupper(md5($password));
- $insert = [
- 'Username' => $username,
- 'Password' => $password,
- 'Email' => $email,
- 'RegisteredTime' => time(),
- 'Color' => '1',
- ];
- $columns = array_keys($insert);
- $values = array_values($insert);
- $query = 'INSERT INTO users (`' . implode('`', $columns) . "`) VALUES ('" .
- implode("'", $values) . "')";
- $insert = $mysqli->query($query);
- if (! $insert) {
- exit('e=28');
- }
- exit('e=0');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement