daily pastebin goal
29%
SHARE
TWEET

Untitled

a guest Jun 18th, 2017 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. echo "acc.php successfully accessed!";
  3.  
  4. //set host, username and password for MySQL
  5. $dbhost = "178.40.61.8";
  6. $dbuser = "root";
  7. $dbpass = "root";
  8.  
  9. //connect to MySQL or return an error
  10. $conn = mysql_connect($dbhost, $dbuser, $dbpass)
  11. or die('Could not connect: ' . mysql_error());
  12.  
  13. var_dump($conn);
  14. die();
  15.  
  16. //set database name
  17. $dbname = "l2jdb";
  18.  
  19. //select database or return an error
  20. $dbselect = mysql_select_db("$dbname")
  21. or die ('Could not select database');
  22.  
  23. //get username and password info from the form, protecting against SQL injection
  24. $pass = mysql_real_escape_string($_POST["pass"]);
  25. $confirm = mysql_real_escape_string($_POST["confirm"]);
  26. $user = mysql_real_escape_string($_POST["name"]);
  27.  
  28. //validate user input
  29. if(!preg_match('/^[a-zA-Z0-9]{5,20}$/',$user)) {
  30. die ('Error: Usernames can only contain alphanumeric characters and must be between 5 and 20 characters in length.');
  31. }
  32.  
  33. if(!preg_match('/^[a-zA-Z0-9]{5,20}$/',$pass)) {
  34. die echo'Error: Passwords can only contain alphanumeric characters and must be between 5 and 20 characters in length.';
  35. }
  36.  
  37. if($pass != $confirm) {
  38. die echo'Error: Passwords do not match.';
  39. }
  40.  
  41. //make sure user doesn't already exist and if it doesn't, add new record to the database
  42. $result = mysql_query("SELECT login FROM accounts WHERE login='$user'");
  43.  
  44. if(mysql_num_rows($result)>0) {
  45. die ('Error: Username already exists.');
  46. }else{
  47. mysql_query("INSERT INTO accounts (login, password, accessLevel) VALUES ('".$_POST['name']."', '".base64_encode(pack('H*', sha1($_POST['pass'])))."', 0)")
  48. or die ('Error: ' . mysql_error());
  49. }
  50.  
  51. //report successful registration
  52. echo "Account created successfully.";
  53.  
  54. //close MySQL connection
  55. mysql_close();
  56.  
  57. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top