Advertisement
Jaamal

register.php for help

Jun 25th, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.59 KB | None | 0 0
  1. //Get all POST data from user trying to register
  2. $username = $_POST['username'];
  3. $password =  $_POST['password'];
  4. $name = $_POST['name'];
  5. $email = $_POST['email'];
  6. $lat = $_POST['lat'];
  7. $lon = $_POST['lon'];
  8.  
  9. //Choose wether the user will be "it" or "not it"
  10. $choose_it = array('it', 'not it');
  11. $key = array_rand($choose_it);
  12. $it = $choose_it[$key];
  13.  
  14. $message = "";
  15.  
  16. $allEmails = "";
  17. $allUnames = "";
  18.  
  19. function strong_crypt($input, $rounds = 81)
  20. {
  21.     $salt = "";
  22.     $salt_chars = array_merge(range('A','Z'), range('a','z'), range(0,9));
  23.        
  24.     for($i=0; $i < 22; $i++)
  25.     {
  26.         $salt .= $salt_chars[array_rand($salt_chars)];
  27.     }
  28.     return crypt($input, sprintf('$2a$%02d$', $rounds) . $salt);
  29. }
  30.  
  31. //Get emails from registered users and check if it has already been used
  32. $AllPeople = "SELECT email, uname FROM login WHERE email = '$email'";
  33. $query = mysqli_query($conn,$AllPeople);
  34.  
  35. while($row = mysqli_fetch_array($query))
  36. {
  37.     $allEmails = $row['email'];
  38.     $allUnames = $row['uname'];
  39. }
  40.  
  41. if($allEmails != "")
  42. {
  43.     $message = "That email already exists. You can only have one account per email address.";
  44. }
  45.  
  46. if($allUnames != "")
  47. {
  48.     $message = "That username has already been taken. Please choose a different one.";
  49. }
  50.                
  51. if($allEmails === "" && $allUnames === "")
  52. {
  53.     $hash = strong_crypt($password);
  54.  
  55.     mysqli_query($conn, "INSERT INTO login (name, uname, pword, email, lat, lon, it) VALUES ('$name', '$username', '$hash', '$email', '$lat', '$lon', '$it')");
  56.    
  57.     $message = "goodtogo";
  58. }
  59.  
  60. echo json_encode(array("message" => $message, "name" => $name, "it" => $it));
  61.  
  62. mysqli_close($conn);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement