Advertisement
Guest User

Untitled

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