daily pastebin goal
58%
SHARE
TWEET

Untitled

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