Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class register extends database
- {
- function __construct($username, $password, $email)
- {
- $this->username = $username;
- $this->password = password_hash($password, PASSWORD_DEFAULT);
- $this->email = $email;
- $this->activation_id = $this->generateActivationId();
- $this->sender_email = 'support@url.com';
- $this->activation_link = 'http://url.com/folder/activate.php?id=' . $this->activation_id;
- $this->database = new database();
- }
- function generateActivationId()
- {
- $generator = bin2hex(random_bytes(10));
- return $generator;
- }
- function registerAccount()
- {
- $this->database->connect();
- $user_lookup = $this->database->execute_query("SELECT * FROM users WHERE username = '" . $this->username . "'");
- if (mysqli_num_rows($user_lookup) > 0)
- {
- return false;
- }
- else
- {
- $this->database->execute_query("INSERT INTO users (username, password, email, activation_id) VALUES ('" . $this->username . "', '" . $this->password . "', '" . $this->email . "', '" . $this->activation_id . "')");
- $user_lookup_comfirm = $this->database->execute_query("SELECT * FROM users WHERE username = '" . $this->username . "'");
- if (mysqli_num_rows($user_lookup_comfirm) > 0)
- {
- $this->sendRegisterEmail();
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- function sendRegisterEmail()
- {
- $subject = 'Registration - Activate your account';
- $message = 'Thank you for registering. Please activate your account by visiting the following site: <a href="' . $this->activation_link . '">Website link</a>';
- $headers = 'From: ' . $this->sender_email . "rn" .
- 'Reply-To: ' . $this->sender_email . "rn" .
- 'X-Mailer: PHP/' . phpversion();
- mail($this->email, $subject, $message, $headers);
- }
- }
- ?>
- <?php
- class database
- {
- function __construct()
- {
- $this->dBusername = 'xxx';
- $this->dBpassword = 'xxx';
- $this->dBhost = 'localhost';
- $this->dBdatabase = 'xxx';
- $this->dBcharset = 'utf8';
- }
- function connect()
- {
- $mysqli = new mysqli($this->dBhost, $this->dBusername, $this->dBpassword, $this->dBdatabase);
- if ($mysqli->connect_errno)
- {
- $this->_mysqli = false;
- }
- else
- {
- $mysqli->set_charset($this->charset);
- $this->_mysqli = $mysqli;
- }
- }
- function execute_query($sql)
- {
- if($results = $this->_mysqli->query($sql))
- {
- return $results;
- }
- else
- {
- return false;
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement