Advertisement
Guest User

Register

a guest
Apr 4th, 2018
563
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.98 KB | None | 0 0
  1. <?php
  2.  
  3. if(isset($_SERVER['HTTP_CF_CONNECTING_IP']) == true)
  4.     $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
  5.  
  6. include_once '../class/assets/dbconfig.php';
  7.  
  8. $username = $_REQUEST['username'];
  9. $password = $_REQUEST['password'];
  10. $email = $_REQUEST['email'];
  11. $confirm = $_REQUEST['confirm'];
  12. $ip = $_SERVER['REMOTE_ADDR'];
  13.  
  14. if(strlen($username) < 3 or strlen($username) > 24)
  15. {
  16.     echo $txtError = ("Username invalido (3 - 24 caratteri)."); return false;
  17. }
  18.  
  19. if(preg_match('/[^A-Za-z0-9_]/', $username) == true)
  20. {
  21.     echo $txtError = ("Caratteri invalidi."); return false;
  22. }
  23.  
  24. if($password != $confirm)
  25. {
  26.     echo $txtError = ("Password diverse."); return false;
  27. }
  28.  
  29. if(strlen($confirm) < 8 or strlen($confirm) > 32)
  30. {
  31.     echo $txtError = ("Password invalida (8 - 32 caratteri).");  return false;
  32. }
  33.  
  34. if(filter_var($email, FILTER_VALIDATE_EMAIL) != true)
  35. {
  36.     echo $txtError = ("Email non valida.");  return false;
  37. }
  38.  
  39. $db = getDB();
  40. $stmt = $db->prepare("SELECT email, username FROM accounts WHERE email=:email OR username=:username");
  41. $stmt->bindParam("email", $email, PDO::PARAM_STR);
  42. $stmt->bindParam("username", $username, PDO::PARAM_STR);
  43. $stmt->execute();
  44. $count = $stmt->rowCount();
  45.  
  46. if($count)
  47. {
  48.     $data = $stmt->fetch(PDO::FETCH_ASSOC);
  49.    
  50.     if($data['email'] == $email) echo $txtError = ("Email già utilizzata.<br>");
  51.     if($data['username'] == $username) echo $txtError = ("Account già registrato.");
  52.    
  53.     return false;
  54. }
  55.  
  56. $tmp_token = random_bytes(8);
  57. $token_register = bin2hex($tmp_token);
  58. $hash_password = hash('whirlpool', $confirm);
  59.  
  60. $stmt = $db->prepare("INSERT INTO accounts (username, password, email, confirmed, created_at, register_token, ip) VALUES (:username, :hash_password, :email, '0', NOW(), :token_register, :ip)");
  61. $stmt->bindParam("username", $username, PDO::PARAM_STR);
  62. $stmt->bindParam("hash_password", $hash_password, PDO::PARAM_STR);
  63. $stmt->bindParam("email", $email, PDO::PARAM_STR);
  64. $stmt->bindParam("token_register", $token_register, PDO::PARAM_STR);
  65. $stmt->bindParam("ip", $ip, PDO::PARAM_STR);
  66. $stmt->execute();
  67.  
  68. $mail_receiver = $email;   
  69. $mail_object = "Registrazione";
  70. $mail_body = "
  71.                 <body>
  72.                 <font size='3'>Benvenuto/a su Los Santos Roleplay, <b>$username</b>.<br>
  73.                 <br>Il sistema richiede la conferma dell'indirizzo email prima di poter utilizzare l'account registrato, si prega quindi di premere sul tasto di seguito per confermarla:
  74.                 <a href='http://ucp.ls-rp.it/send/account_confirm.php?key=$token_register'>Pagina attivazione</a>.<br>
  75.                 <br>Link: http://ucp.ls-rp.it/send/account_confirm.php?key=$token_register<br>
  76.                 Una volta cliccato sul link, sarai reinderizzato alla pagina di login. Inserisci i tuoi dati e potrai utilizzare l'account.<br>
  77.                 <br>Distinti saluti, lo staff di <b>Los Santos Roleplay</b>.
  78.                 </body>
  79.             ";
  80.  
  81. include '../core/emailconfig.php';
  82.  
  83. echo $txtError = ("Account creato.<br>Controlla la tua email per confermarlo.<br>Clicca <a href='index.php'>qui</a> per andare al login.");
  84.  
  85. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement