daily pastebin goal
15%
SHARE
TWEET

Untitled

a guest Jun 18th, 2017 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. require './conn/conn.php';
  3.  
  4. //connect to MySQL or return an error
  5. $conn = mysql_connect($dbhost, $dbuser, $dbpass)
  6. or die('Could not connect: ' . mysql_error());
  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');
  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. //validate user input
  21. if(!preg_match('/^[a-zA-Z0-9]{5,20}$/',$user)) {
  22. die ('Error: Usernames can only contain alphanumeric characters and must be between 5 and 20 characters in length.');
  23. }
  24.  
  25. if(!preg_match('/^[a-zA-Z0-9]{5,20}$/',$pass)) {
  26. die('Error: Passwords can only contain alphanumeric characters and must be between 5 and 20 characters in length.');
  27. }
  28.  
  29. if($pass != $confirm) {
  30. die('Error: Passwords do not match.');
  31. }
  32.  
  33. //make sure user doesn't already exist and if it doesn't, add new record to the database
  34. $result = mysql_query("SELECT login FROM accounts WHERE login='$user'");
  35.  
  36. if(mysql_num_rows($result)>0) {
  37. die ('Error: Username already exists.');
  38. }else{
  39. mysql_query("INSERT INTO accounts (login, password, accessLevel) VALUES ('".$_POST['name']."', '".base64_encode(pack('H*', sha1($_POST['pass'])))."', 0)")
  40. or die ('Error: ' . mysql_error());
  41. }
  42.  
  43. //report successful registration
  44. echo "Account created successfully.";
  45.  
  46. //close MySQL connection
  47. mysql_close();
  48.  
  49. ?>
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
Pastebin PRO 'WINTER SPECIAL'!
Get 40% OFF Pastebin PRO accounts!
 
Top