Guest User

Untitled

a guest
Apr 18th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.06 KB | None | 0 0
  1. <?php
  2. $realmd = array(
  3. 'db_host'=> 'localhost',        // Host IP
  4. 'db_username' => '',        // Database login-name
  5. 'db_password' => '',      // Database login-pass
  6. 'db_name_realm'=> '',     // Database name of realm
  7. );
  8.  
  9. function check_for_symbols($string)
  10. {
  11.     $len=strlen($string);
  12.     $allowed_chars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  13.     for($i=0;$i<$len;$i++)if(!strstr($allowed_chars,$string[$i]))
  14.         return TRUE;
  15.     return FALSE;
  16. }
  17. function sha_password($user,$pass)
  18. {
  19.     $user = strtoupper($user);
  20.     $pass = strtoupper($pass);
  21.     return SHA1($user.':'.$pass);
  22. }
  23. if ($realmd[db_host] != "" && $realmd[db_username] != "" && $realmd[db_password] != "" && $realmd[db_name_realm] != "")
  24. {
  25.     $new_connect = mysql_connect($realmd[db_host],$realmd[db_username],$realmd[db_password]);
  26.     if ($new_connect)
  27.         $selectdb = mysql_select_db($realmd[db_name_realm],$new_connect);
  28.     else
  29.     {
  30.         echo "Could NOT connect to db: Configs (Name/Pass/Port/IP) are incorrect";
  31.         die;
  32.     }
  33.  
  34.     if ($new_connect && !$selectdb)
  35.     {
  36.         echo "Could NOT connect to db: Database does not exist!";
  37.         die;
  38.     }
  39.  
  40.     if ($_POST['registration'])
  41.     {
  42.         $username = $_POST['username'];
  43.         $password = sha_password($username,$_POST['password']);
  44.         $passcheck1 = $_POST['password'];
  45.         $passcheck2 = $_POST['password2'];
  46.         $email = $_POST['email'];
  47.                 $email2 = $_POST['email2'];
  48.         $expansionnumber = $_POST['expansion'];
  49.  
  50.         $check_username = mysql_query("SELECT username FROM `account` WHERE username='$username'");
  51.         if ($username == "")
  52.         {
  53.             echo "Username is empty!";
  54.         }
  55.         else if ($password == "")
  56.         {
  57.             echo "Password is empty!";
  58.         }
  59.                 else if ($passcheck2 == "")
  60.                 {
  61.                         echo "Please confirm your password!";
  62.                 }
  63.         else if (check_for_symbols($_POST[password]) == TRUE)
  64.         {
  65.             echo "Error with creating account: password has invalid symbols in it.";
  66.         }
  67.         else if (check_for_symbols($username) == TRUE)
  68.         {
  69.             echo "Error with creating account: username has invalid symbols in it.";
  70.         }
  71.         else if (mysql_num_rows($check_username) != 0)
  72.         {
  73.             echo "Error with creating account: name is already in use.";
  74.         }
  75.                 else if ($passcheck1 != $passcheck2)
  76.                 {
  77.                         echo "Passwords don't match!";
  78.                 }
  79.                 else if ($email == "")
  80.                 {
  81.                         echo "Email is empty!";
  82.                 }
  83.                 else if ($email2 == "")
  84.                 {
  85.                         echo "Please confirm your email!";
  86.                 }
  87.                 else if ($email != $email2)
  88.                 {
  89.                         echo "Emails don't match!";
  90.                 }
  91.         else
  92.         {
  93.             $username = mysql_real_escape_string($username);
  94.                         $email = mysql_real_escape_string($email);
  95.             mysql_query("INSERT INTO account (username,sha_pass_hash,email,expansion) VALUES
  96. ('$username','$password','$email','$expansionnumber')");
  97.             if (mysql_error)
  98.                 echo mysql_errno($new_connect) . ": " . mysql_error($new_connect). "\n";
  99.             else
  100.             {
  101.                 echo "Account created.";
  102.                 mysql_close($new_connect);
  103.             }
  104.         }
  105.     }
  106.     else
  107.     {
  108.         ?>
  109.         <html>
  110.         <head>
  111.         <title>Регистрация Аккаунт Battleage.kg</title>
  112.         </head>
  113.         <body>
  114.         <center><br><br><img src="logo.png"><br><br></center>
  115. <table width="30%" border="1" align="center">
  116.   <tr>
  117.     <td><center>Регистрация аккаунта</center></td>
  118.   </tr>
  119.   <tr>
  120.     <td><center><form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST">
  121.       <table width="100%" border="1">
  122.         <tr>
  123.           <td width="50%">Логин:</td>
  124.           <td width="50%"><input type="text" name="username" /></td>
  125.         </tr>
  126.         <tr>
  127.           <td>Пароль:<br/>
  128.             Подверждение пароля:</td>
  129.           <td width="50%"><input type="password" name="password" />            <input type="password" name="password2" /></td>
  130.         </tr>
  131.         <tr>
  132.           <td>Expansion Selection:</td>
  133.           <td width="50%"><select name="expansion">
  134.             <option selected value="2">WotLK</option>
  135.             </select></td>
  136.         </tr>
  137.         <tr>
  138.           <td>Email:<br/>
  139.             Подверждение Email:</td>
  140.           <td width="50%"><input type="text" name="email" />            <input type="text" name="email2" /></td>
  141.         </tr>
  142.         </table>
  143.         <input type="submit" name="registration" />
  144.       </p>
  145.     </form></center></td>
  146.   </tr>
  147. </table>
  148.     </body>
  149.         </html>
  150.         <?php
  151.     }
  152. }
  153. else
  154. {
  155.     echo "Config file either not present or connection variables are empty";
  156.  
  157. }
  158. ?>
Add Comment
Please, Sign In to add comment