Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.47 KB | None | 0 0
  1. <?php
  2. require './conn/connect.php';
  3.  
  4. //connect to MySQL or return an error
  5. $conn = @mysql_connect($dbhost, $dbuser, $dbpass)
  6. or die('Could not connect , Try it later ...');
  7.  
  8. //set database name
  9. $dbname = "l2jdb";
  10.  
  11. //select database or return an error
  12. $dbselect = mysql_select_db("$dbname")
  13. or die ('Could not select database , Try it later ...');
  14.  
  15. //get username and password info from the form, protecting against SQL injection
  16. $pass = mysql_real_escape_string($_POST["pass"]);
  17. $confirm = mysql_real_escape_string($_POST["confirm"]);
  18. $user = mysql_real_escape_string($_POST["name"]);
  19. $email = mysql_real_escape_string($_POST["mail"]);
  20.  
  21. if($_POST['submit'])
  22. {
  23.     if( $pass == "" || $confirm == "" || $user == "" || $email == "" )
  24.     {
  25.         //validate user input
  26.         if(!preg_match('/^[a-zA-Z0-9]{5,14}$/',$user))
  27.         {
  28.             header("Location: account-1.html");
  29.             die();
  30.             //die ('Usernames can only contain alphanumeric characters and must be between 5 and 20 characters in length.');
  31.         }
  32.         else if(!preg_match('/^[a-zA-Z0-9]{5,20}$/',$pass))
  33.         {
  34.             header("Location: account-1.html");
  35.             die();
  36.             //die('Passwords can only contain alphanumeric characters and must be between 5 and 20 characters in length.');
  37.         }
  38.         else if($pass != $confirm)
  39.         {
  40.             header("Location: account-1.html");
  41.             die();
  42.         }
  43.         else
  44.         {
  45.             //make sure user doesn't already exist and if it doesn't, add new record to the database
  46.             $result = mysql_query("SELECT login FROM accounts WHERE login='$user'");
  47.             $mailresult = mysql_query("SELECT email FROM account_email WHERE email='$email'");
  48.            
  49.             if(mysql_num_rows($result)>0 || mysql_num_rows($mailresult)>0)
  50.             {
  51.                 echo "Email or account allready in use . choose a other account or email .";
  52.                 die();
  53.                 //die ('Username already exists.');
  54.             }
  55.             else
  56.             {
  57.                 mysql_query("INSERT INTO accounts (login, password, accessLevel) VALUES ('".$_POST['name']."', '".base64_encode(pack('H*', sha1($_POST['pass'])))."', 0)");
  58.                 mysql_query("INSERT INTO account_email (login, email) VALUES ('".$_POST['name']."', '".$_POST['mail']."')")
  59.                 or die ('Error: ' . mysql_error());
  60.             }
  61.            
  62.                 //report successful registration
  63.                 //header("Location: account-5.html");
  64.             echo "Account created successfully.";
  65.  
  66.             //close MySQL connection
  67.             mysql_close();
  68.         }
  69.     }
  70.     else
  71.     {
  72.         echo "Full informations right !";
  73.     }
  74. }
  75. else
  76. {
  77.     echo "Account Manager for Lineage 2 Avocado<br>Leave This Page :)";
  78.     //close MySQL connection
  79.     mysql_close();
  80. }
  81. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement