Advertisement
Guest User

Untitled

a guest
May 30th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.26 KB | None | 0 0
  1. <?php
  2.     // set the config values for connecting to the db
  3.     $dbhost = "127.0.0.1";
  4.     $dbuser = "root";
  5.     $dbpassword = "P@ssw0rd";
  6.     $db = "arcemu_logon";
  7.    
  8.     // misc config
  9.     $accountcreated = "<div style='background-color:green; color:white; font-weight:bold;'>Your account ".$login." has been created!</div>";
  10.     $allow_multi_email = true;
  11.     $allow_multi_ip = true;
  12.        
  13.     echo '
  14.         <html>
  15.             <head>
  16.                 <title>WoWPS Account Creation</title>
  17.             </head>
  18.             <body>
  19.     ';
  20.    
  21.     if (!isset($_POST['login'])) {
  22.         form();
  23.     } else {       
  24.         // connect to the db
  25.         $dbcon = mysql_connect($dbhost,$dbuser,$dbpassword) or die(mysql_error());
  26.         mysql_select_db($db,$dbcon) or die(mysql_error());
  27.        
  28.         // get login, password, email from form
  29.         $login = !get_magic_quotes_gpc() ? mysql_real_escape_string($_POST['login']) : $_POST['login'];
  30.         $password = !get_magic_quotes_gpc() ? mysql_real_escape_string($_POST['password']) : $_POST['password'];
  31.         $email = !get_magic_quotes_gpc() ? mysql_real_escape_string($_POST['email']) : $_POST['email'];
  32.         $ip = $_SERVER['REMOTE_ADDR'];
  33.        
  34.         if (valid_info($login,$password,$email,$ip,$allow_multi_email,$allow_multi_ip)) {      
  35.             // encrypt the password for putting in to db
  36.             $sha1pass = sha1(strtoupper($login).":".strtoupper($password));
  37.  
  38.             // make sure data gets put in or display error
  39.             if (mysql_query("INSERT INTO accounts(login,password,encrypted_password,gm,email,flags,lastip) VALUES('$login','$password','$sha1pass',0,'$email',24,'$ip')")) {
  40.                 mysql_close($dbcon);  
  41.                 echo $accountcreated;
  42.             } else {
  43.                 switch(mysql_errno()) {
  44.                     case 1062 :
  45.                         echo "<div style='background-color:red; color:white; font-weight:bold;'>This accounts already exist !</div> ".form();
  46.                     break;
  47.                    
  48.                     default :
  49.                         echo "Mysql Error : ".mysql_errno()."<br />".form();
  50.                     break;
  51.                 }
  52.             }
  53.         }
  54.     }
  55.    
  56.     echo '
  57.             </body>
  58.         </html>
  59.     ';
  60.    
  61.     function form() {
  62.         echo '
  63.             <form action="./" method="post">
  64.                 <table>
  65.                     <tr><td>Login : (6 chars min) </td><td><input name="login" value="" type="text"></td></tr>
  66.                     <tr><td>Password : (6 chars min) </td><td><input name="password" value="" type="password"></td></tr>
  67.                     <tr><td>Email : </td><td><input name="email" value="" type="text"></td></tr>
  68.                     <tr><td colspan="2" align="center"><input type="submit"></td></tr>
  69.                 </table>
  70.             </form>
  71.         ';
  72.     }
  73.    
  74.     function valid_info($login,$password,$email,$ip,$allow_multi_email,$allow_multi_ip) {
  75.        
  76.         // check for valid password and login
  77.         if (preg_match('/[^0-9A-Za-z]/',$login)) {
  78.             echo "<div style='background-color:red; color:white; font-weight:bold;'>Login is invalid. Only a-z, A-Z, and numbers allowed!</div>".form();
  79.             return false;
  80.         }
  81.        
  82.         // check for blank login or password or email
  83.         if ($login == "" || $password == "" || $email == "") {
  84.             echo "<div style='background-color:red; color:white; font-weight:bold;'>Login, password, or email is blank, please fill them out! !</div>".form();
  85.             return false;
  86.         }
  87.        
  88.         // check if login and password is over 5 characters long
  89.         if (strlen($login) <= 5 || strlen($password) <= 5) {
  90.             echo "<div style='background-color:red; color:white; font-weight:bold;'>Login or password was under 6 characters long !</div>".form();
  91.             return false;
  92.         }
  93.        
  94.         // check for valid email
  95.             if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  96.             echo "<div style='background-color:red; color:white; font-weight:bold;'>Invalid email address!</div>".form();
  97.             return false;
  98.         }
  99.        
  100.         // if we don't allow an email to be used on more then one account warn the user
  101.         if (!$allow_multi_email) {
  102.             if (mysql_num_rows(mysql_query("SELECT email FROM accounts WHERE email = '$email'")) > 0) {
  103.                 echo "<div style='background-color:red; color:white; font-weight:bold;'>Email already in use!</div>".form();
  104.                 return false;              
  105.             }
  106.         }
  107.        
  108.         // if we don't allow an ip to be on more then one account then warn the user
  109.         if (!$allow_multi_ip) {
  110.             if (mysql_num_rows(mysql_query("SELECT * FROM accounts WHERE lastip = '$ip'")) > 0) {
  111.                 echo "<div style='background-color:red; color:white; font-weight:bold;'>This IP has already made an account!</div>".form();
  112.                 return false;
  113.             }
  114.         }
  115.        
  116.         return true;
  117.     }
  118. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement