Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.44 KB | None | 0 0
  1. <?php
  2.  
  3. require_once("config.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. ?>
  74.  
  75. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  76. <html xmlns="http://www.w3.org/1999/xhtml">
  77. <head>
  78. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />
  79. <link rel="stylesheet" type="text/css" href="site.css" />
  80. <meta name="description" content="<?php $site["meta_description"] ?>" />
  81. <meta name="keywords" content="<?php echo $site["meta_keywords"]; ?>" />
  82. <meta name="robots" content="<?php echo $site["meta_robots"] ?>" />
  83. <meta name="author" content="Jordy Thery" />
  84. <link rel="shortcut icon" href="img/favicon.png" type="image/png" />
  85. <title><?php echo $site["title"]; ?></title>
  86. </head>
  87. <body>
  88.  
  89.  <script type="text/javascript">
  90.  function checkform ( form )
  91.  {
  92.  
  93.      if (form.accountname.value == "") { alert( "You did not fill in your account name. Please try again." ); form.accountname.focus(); return false; } else { if (form.accountname.value.length < 3) { alert( "Az account neved túl rövid!" ); form.accountname.focus(); return false; } }
  94.      if (form.password.value == "") { alert( "You did not fill in a password. Please try again." ); form.password.focus(); return false; } else { if (form.password.value.length < 6) { alert( "A jelszavad túl rövid!" ); form.password.focus(); return false; } }
  95.      if (form.password2.value == "") { alert( "You did not fill in a password. Please try again." ); form.password2.focus(); return false; }
  96.      if (form.password.value == form.accountname.value) { alert( "The passwords do not patch. Please try again." ); form.password.focus(); return false; }
  97.      if (form.password.value != form.password2.value) { alert( "The passwords do not match. Please try again." ); form.password.focus(); return false; }
  98.      if (form.email.value == "") { alert( "You did not fill in your e-mail address. Please try again." ); form.email.focus(); return false; } else { if (form.email.value.length < 8) { alert( "Az email címed túl rövid!" ); form.email.focus(); return false; } }
  99.      if (form.security.value == "") { alert( "You did not fill in the security question. Please try again." ); form.security.focus(); return false; }
  100.  
  101.  return true ;
  102.  }
  103.  </script>
  104.  
  105. <table class="reg">
  106.     <tr>
  107.         <td>
  108.             <a href="<?php echo $_SERVER["PHP_SELF"]; ?>"><img src="img/logo.png" alt="<?php echo $site["title"]; ?>" /></a>
  109.         </td>
  110.     </tr>
  111.     <tr>
  112.         <td>
  113.         </td>
  114.     </tr>
  115.     <tr>
  116.         <td>
  117.        
  118.         <?php error_msg(); ?>
  119.            
  120.             <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="POST" onsubmit="return checkform(reg);" name="reg">
  121.            
  122.             <table class="form">
  123.                 <tr>
  124.                     <td align="right">
  125.                         Account name:
  126.                     </td>
  127.                     <td align="left">
  128.                         <input name="accountname" type="text" maxlength="32" />
  129.                     </td>
  130.                 </tr>
  131.                 <tr>
  132.                     <td align="right">
  133.                         Password:
  134.                     </td>
  135.                     <td align="left">
  136.                         <input name="password" type="password" maxlength="32" />
  137.                     </td>
  138.                 </tr>
  139.                 <tr>
  140.                     <td align="right">
  141.                         Confirm password:
  142.                     </td>
  143.                     <td align="left">
  144.                         <input name="password2" type="password" maxlength="32" />
  145.                     </td>
  146.                 </tr>
  147.                 <tr>
  148.                     <td align="right">
  149.                         E-mail address:
  150.                     </td>
  151.                     <td align="left">
  152.                         <input name="email" type="text" maxlength="32" />
  153.                     </td>
  154.                 </tr>
  155.                 <tr>
  156.                     <td align="right">
  157.                         Expantion:
  158.                     </td>
  159.                     <td align="left">
  160.                         <select name="expansion">
  161.                             <option SELECTED value="2">Cronus's WOW</option>
  162.                         </select>
  163.                     </td>
  164.                 </tr>
  165.                 <tr>
  166.                     <td align="right">
  167.                         Capacha: <font style="color:#00b0f2;"><?php echo $security; ?></font>
  168.                     </td>
  169.                     <td align="left">
  170.                         <input name="security" type="text" maxlength="5" />
  171.                     </td>
  172.                 </tr>
  173.                 <tr>
  174.                     <td colspan="2" align="center">
  175.                         <input type="submit" class="sbm" value="Register" />
  176.                     </td>
  177.                 </tr>
  178.             </table>
  179.            
  180.             </form>
  181.            
  182.             <div class="copy"><b><?php echo $site["realmlist"]; ?></b><br /></div>
  183.  
  184.         </td>
  185.     </tr>
  186. </table>
  187.  
  188. </body>
  189. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement