Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.30 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.     //validate user input
  24.     if(!preg_match('/^[a-zA-Z0-9]{5,20}$/',$user)) {
  25.     header("Location: account-1.html");
  26.     die();
  27.     //die ('Usernames can only contain alphanumeric characters and must be between 5 and 20 characters in length.');
  28.     }
  29.  
  30.     if(!preg_match('/^[a-zA-Z0-9]{5,20}$/',$pass)) {
  31.     header("Location: account-1.html");
  32.     die();
  33.     //die('Passwords can only contain alphanumeric characters and must be between 5 and 20 characters in length.');
  34.     }
  35.    
  36.     if($email == "")
  37.     {
  38.         echo "Email not fulled";
  39.         die();
  40.     }
  41.    
  42.     if($pass != $confirm) {
  43.     header("Location: account-1.html");
  44.     die();
  45.     }
  46.  
  47.     //make sure user doesn't already exist and if it doesn't, add new record to the database
  48.     $result = mysql_query("SELECT login FROM accounts WHERE login='$user'");
  49.     $mailresult = mysql_query("SELECT login FROM accounts WHERE login='$email'");
  50.  
  51.     if(mysql_num_rows($result)>0 || mysql_num_rows($mailresult)>0)
  52.     {
  53.         echo "Email or account allready in use . choose a other account or email .";
  54.         die();
  55.         //die ('Username already exists.');
  56.     }
  57.     else
  58.     {
  59.         mysql_query("INSERT INTO accounts (login, password, accessLevel) VALUES ('".$_POST['name']."', '".base64_encode(pack('H*', sha1($_POST['pass'])))."', 0)");
  60.         mysql_query("INSERT INTO account_email (login, email) VALUES ('".$_POST['name']."', '".$_POST['mail']."')")
  61.         or die ('Error: ' . mysql_error());
  62.     }
  63.  
  64.     //report successful registration
  65.     //header("Location: account-5.html");
  66.     echo "Account created successfully.";
  67.  
  68.     //close MySQL connection
  69.     mysql_close();
  70. }
  71. else
  72. {
  73.     echo "Account Manager for Lineage 2 Avocado<br>Leave This Page :)";
  74.     //close MySQL connection
  75.     mysql_close();
  76. }
  77. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement