Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. <?php
  2. class register extends database
  3. {
  4. function __construct($username, $password, $email)
  5. {
  6. $this->username = $username;
  7. $this->password = password_hash($password, PASSWORD_DEFAULT);
  8. $this->email = $email;
  9. $this->activation_id = $this->generateActivationId();
  10. $this->sender_email = 'support@url.com';
  11. $this->activation_link = 'http://url.com/folder/activate.php?id=' . $this->activation_id;
  12. $this->database = new database();
  13. }
  14.  
  15. function generateActivationId()
  16. {
  17. $generator = bin2hex(random_bytes(10));
  18. return $generator;
  19. }
  20.  
  21. function registerAccount()
  22. {
  23. $this->database->connect();
  24. $user_lookup = $this->database->execute_query("SELECT * FROM users WHERE username = '" . $this->username . "'");
  25.  
  26. if (mysqli_num_rows($user_lookup) > 0)
  27. {
  28. return false;
  29. }
  30. else
  31. {
  32. $this->database->execute_query("INSERT INTO users (username, password, email, activation_id) VALUES ('" . $this->username . "', '" . $this->password . "', '" . $this->email . "', '" . $this->activation_id . "')");
  33. $user_lookup_comfirm = $this->database->execute_query("SELECT * FROM users WHERE username = '" . $this->username . "'");
  34.  
  35. if (mysqli_num_rows($user_lookup_comfirm) > 0)
  36. {
  37. $this->sendRegisterEmail();
  38. return true;
  39. }
  40. else
  41. {
  42. return false;
  43. }
  44. }
  45. }
  46.  
  47. function sendRegisterEmail()
  48. {
  49. $subject = 'Registration - Activate your account';
  50. $message = 'Thank you for registering. Please activate your account by visiting the following site: <a href="' . $this->activation_link . '">Website link</a>';
  51. $headers = 'From: ' . $this->sender_email . "rn" .
  52. 'Reply-To: ' . $this->sender_email . "rn" .
  53. 'X-Mailer: PHP/' . phpversion();
  54.  
  55. mail($this->email, $subject, $message, $headers);
  56. }
  57. }
  58. ?>
  59.  
  60. <?php
  61. class database
  62. {
  63. function __construct()
  64. {
  65. $this->dBusername = 'xxx';
  66. $this->dBpassword = 'xxx';
  67. $this->dBhost = 'localhost';
  68. $this->dBdatabase = 'xxx';
  69. $this->dBcharset = 'utf8';
  70. }
  71.  
  72. function connect()
  73. {
  74. $mysqli = new mysqli($this->dBhost, $this->dBusername, $this->dBpassword, $this->dBdatabase);
  75.  
  76. if ($mysqli->connect_errno)
  77. {
  78. $this->_mysqli = false;
  79. }
  80. else
  81. {
  82. $mysqli->set_charset($this->charset);
  83. $this->_mysqli = $mysqli;
  84. }
  85. }
  86.  
  87. function execute_query($sql)
  88. {
  89. if($results = $this->_mysqli->query($sql))
  90. {
  91. return $results;
  92. }
  93. else
  94. {
  95. return false;
  96. }
  97. }
  98. }
  99. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement