Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once '/var/www/html/forum/library/XenForo/Autoloader.php';
- ini_set('display_errors', 1);
- ini_set('display_startup_errors', 1);
- error_reporting(E_ALL);
- class Xenforo extends Plugin
- {
- /**
- * Runtime values
- */
- private $username;
- private $password;
- private $email;
- private $db;
- /**
- * Receive the user information
- * @param String $username
- * @param String $password
- * @param String email
- */
- public function register($username, $password, $email)
- {
- $this->username = $username;
- $this->password = $password;
- $this->email = $email;
- $this->db = $this->CI->load->database($this->CI->config->item('bridge'), TRUE);
- $this->generate($password);
- $this->authenticate($userId, $password);
- $this->process();
- }
- /**
- * Add the account
- */
- private function process()
- {
- //Insert the User.
- $this->db->query("INSERT INTO ".$this->CI->config->item('forum_table_prefix')."
- xf_user(`username`, `email`, `activity_visible`, `visible`, user_group_id`, `display_style_group_id`, `permission_combination_id`, register_date`, `user_state`, `language_id`)
- VALUES(?, ?, '1', '1', '2', '2', '2', 'valid', '1')",
- array($this->username, $this->email, time()));
- //Insert the User Password in the Authentication Database.
- $this->db->query("INSERT INTO ".$this->CI->config->item('forum_table_prefix')."
- xf_user_authentication(`user_id`, `scheme_class`, `data`, `remember_key`)
- VALUES(?, 'XenForo_Authentication_Core12', ?, ?)", /*Here we set the Base Authentication method! "XenForo_Authentication_Core12"*/
- array($this->password));
- }
- /**
- * Use the XenForo base Class & generate a Hashcode
- * Define here the XenForo Autoloader to use the XenForo Base filesystem!
- */
- public function __construct()
- {
- $startTime = microtime(true);
- XenForo_Autoloader::getInstance()->setupAutoloader('/var/www/html/forum/library');
- XenForo_Application::initialize('/var/www/html/forum/library');
- XenForo_Application::set('page_start_time', $startTime);
- XenForo_Session::startPublicSession();
- }
- /**
- * Generate new authentication data
- * @see XenForo_Authentication_Abstract::generate()
- */
- protected function generate($password)
- {
- $passwordHash = new XenForo_PasswordHash(XenForo_Application::getConfig()->passwordIterations, false);
- $output = array('hash' => $passwordHash->HashPassword($password));
- return serialize($output);
- }
- /**
- * Authenticate against the given password
- * @see XenForo_Authentication_Abstract::authenticate()
- */
- protected function authenticate($userId, $password)
- {
- if (!is_string($password) || $password === '' || empty($this->_data))
- {
- return false;
- }
- $passwordHash = new XenForo_PasswordHash(XenForo_Application::getConfig()->passwordIterations, false);
- return $passwordHash->CheckPassword($password, $this->_data['hash']);
- }
- protected function isUpgradable()
- {
- if (!empty($this->_data['hash']))
- {
- $passwordHash = new XenForo_PasswordHash(XenForo_Application::getConfig()->passwordIterations, false);
- $expectedIterations = min(intval(XenForo_Application::getConfig()->passwordIterations), 30);
- $iterations = null;
- if (preg_match('/^\$(P|H)\$(.)/i', $this->_data['hash'], $match))
- {
- $iterations = $passwordHash->reverseItoA64($match[2]) - 5; // 5 iterations removed in PHP 5
- }
- else if (preg_match('/^\$2a\$(\d+)\$.*$/i', $this->_data['hash'], $match))
- {
- $iterations = intval($match[1]);
- }
- return $expectedIterations !== $iterations;
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement