Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.47 KB | None | 0 0
  1. <?php
  2.  
  3. require_once("config10.php");
  4.  
  5. session_start();
  6.  
  7. if(!empty($_POST["security"])){
  8.  
  9.     if($_SESSION["security"]  != $_POST["security"]) { $errors[] = "Invalid input. Please try again."; }
  10.  
  11. }
  12.  
  13. $security = rand(10000, 100000);
  14. $_SESSION["security"] = $security;
  15.  
  16. if(!empty($_POST["accountname"]) && !empty($_POST["password"]) && !empty($_POST["password2"]) && !empty($_POST["email"]) && $_POST["expansion"] != "" && !empty($_POST["security"])){
  17.  
  18.     $mysql_connect = mysqli_connect($mysql["host"], $mysql["username"], $mysql["password"]) or die("Unable to connect to the database.");
  19.     mysqli_select_db($mysql_connect, $mysql["realmd"]) or die("Unable to select logon database.");
  20.    
  21.     $post_accountname = mysqli_real_escape_string($mysql_connect, trim(strtoupper($_POST["accountname"])));
  22.     $post_password = mysqli_real_escape_string($mysql_connect, trim(strtoupper($_POST["password"])));
  23.     $post_password_final = mysqli_real_escape_string($mysql_connect, SHA1("".$post_accountname.":".$post_password.""));
  24.     $post_password2 = trim(strtoupper($_POST["password2"]));
  25.     $post_email = mysqli_real_escape_string($mysql_connect, trim($_POST["email"]));
  26.     $post_expansion = mysqli_real_escape_string($mysql_connect, trim($_POST["expansion"]));
  27.    
  28.     $check_account_query = mysqli_query($mysql_connect, "SELECT COUNT(*) FROM account WHERE username = '".$post_accountname."'");
  29.     $check_account_results = mysqli_fetch_array($check_account_query);
  30.     if($check_account_results[0]!=0){ $errors[] = "The requested account name is already in use. Please try again."; }
  31.    
  32.     if(strlen($post_accountname) < 3) { $errors[] = "The requested account name is to short. Please try again."; }
  33.     if(strlen($post_accountname) > 32) { $errors[] = "The requested account name is to long. Please try again."; }
  34.     if(strlen($post_password) < 6) { $errors[] = "The requested password is to short. Please try again."; }
  35.     if(strlen($post_password) > 32) { $errors[] = "The requested password is to long. Please try again."; }
  36.     if(strlen($post_email) > 64) { $errors[] = "The requested e-mail address is to long. Please try again."; }
  37.     if(strlen($post_email) < 8) { $errors[] = "The requested e-mail address is to short. Please try again."; }
  38.     if(!ereg("^[0-9a-zA-Z%]+$", $post_accountname)) { $errors[] = "Your account name can only contain letters or numbers. Please try again."; }
  39.     if(!ereg("^[0-9a-zA-Z%]+$", $post_password)) { $errors[] = "Your password can only contain letters or numbers. Please try again."; }
  40.     if(!ereg("^[0-2%]+$", $post_expansion)) { $errors[] = "Invalid input. Please try again."; }
  41.     if(strlen($post_expansion) > 1) { $errors[] = "Invalid input. Please try again."; }
  42.     if($post_accountname == $post_password) { $errors[] = "The passwords do not match. Please try again."; }
  43.     if($post_password != $post_password2) { $errors[] = "The passwords do not match. Please try again."; }
  44.    
  45.     if(!is_array($errors)){
  46.    
  47.         mysqli_query($mysql_connect, "INSERT INTO account (username, sha_pass_hash, email, last_ip, expansion) VALUES ('".$post_accountname."', '".$post_password_final."', '".$post_email."', '".$_SERVER["REMOTE_ADDR"]."', '".$post_expansion."')") or die(mysqli_error($mysql_connect));
  48.        
  49.     $errors[] = 'You have successfully created the account: <font color="yellow">'.$post_accountname.'</font>.';  
  50.    
  51.     }
  52.    
  53.     mysqli_close($mysql_connect);
  54.  
  55. }
  56.  
  57. function error_msg(){
  58.  
  59.     global $errors;
  60.    
  61.     if(is_array($errors)){
  62.    
  63.         foreach($errors as $msg){
  64.        
  65.             echo '<div class="errors">'.$msg.'</div>';
  66.        
  67.         }
  68.    
  69.     }
  70.  
  71. }
  72.  
  73. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement