Advertisement
Guest User

Untitled

a guest
Feb 15th, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.87 KB | None | 0 0
  1. <?php
  2.  
  3. require_once '/var/www/html/forum/library/XenForo/Autoloader.php';
  4.  
  5. ini_set('display_errors', 1);
  6. ini_set('display_startup_errors', 1);
  7. error_reporting(E_ALL);
  8.  
  9. class Xenforo extends Plugin
  10. {
  11. /**
  12. * Runtime values
  13. */
  14. private $username;
  15. private $password;
  16. private $email;
  17. private $db;
  18.  
  19. /**
  20. * Receive the user information
  21. * @param String $username
  22. * @param String $password
  23. * @param String email
  24. */
  25. public function register($username, $password, $email)
  26. {
  27. $this->username = $username;
  28. $this->password = $password;
  29. $this->email = $email;
  30. $this->db = $this->CI->load->database($this->CI->config->item('bridge'), TRUE);
  31.  
  32. $this->generate($password);
  33. $this->authenticate($userId, $password);
  34.  
  35. $this->process();
  36. }
  37.  
  38. /**
  39. * Add the account
  40. */
  41. private function process()
  42. {
  43. //Insert the User.
  44. $this->db->query("INSERT INTO ".$this->CI->config->item('forum_table_prefix')."
  45. xf_user(`username`, `email`, `activity_visible`, `visible`, user_group_id`, `display_style_group_id`, `permission_combination_id`, register_date`, `user_state`, `language_id`)
  46. VALUES(?, ?, '1', '1', '2', '2', '2', 'valid', '1')",
  47. array($this->username, $this->email, time()));
  48.  
  49. //Insert the User Password in the Authentication Database.
  50. $this->db->query("INSERT INTO ".$this->CI->config->item('forum_table_prefix')."
  51. xf_user_authentication(`user_id`, `scheme_class`, `data`, `remember_key`)
  52. VALUES(?, 'XenForo_Authentication_Core12', ?, ?)", /*Here we set the Base Authentication method! "XenForo_Authentication_Core12"*/
  53. array($this->password));
  54. }
  55.  
  56. /**
  57. * Use the XenForo base Class & generate a Hashcode
  58. * Define here the XenForo Autoloader to use the XenForo Base filesystem!
  59. */
  60.  
  61. public function __construct()
  62. {
  63. $startTime = microtime(true);
  64. XenForo_Autoloader::getInstance()->setupAutoloader('/var/www/html/forum/library');
  65. XenForo_Application::initialize('/var/www/html/forum/library');
  66. XenForo_Application::set('page_start_time', $startTime);
  67. XenForo_Session::startPublicSession();
  68. }
  69.  
  70. /**
  71. * Generate new authentication data
  72. * @see XenForo_Authentication_Abstract::generate()
  73. */
  74. protected function generate($password)
  75. {
  76. $passwordHash = new XenForo_PasswordHash(XenForo_Application::getConfig()->passwordIterations, false);
  77. $output = array('hash' => $passwordHash->HashPassword($password));
  78. return serialize($output);
  79. }
  80.  
  81. /**
  82. * Authenticate against the given password
  83. * @see XenForo_Authentication_Abstract::authenticate()
  84. */
  85. protected function authenticate($userId, $password)
  86. {
  87. if (!is_string($password) || $password === '' || empty($this->_data))
  88. {
  89. return false;
  90. }
  91.  
  92. $passwordHash = new XenForo_PasswordHash(XenForo_Application::getConfig()->passwordIterations, false);
  93. return $passwordHash->CheckPassword($password, $this->_data['hash']);
  94. }
  95.  
  96. protected function isUpgradable()
  97. {
  98. if (!empty($this->_data['hash']))
  99. {
  100. $passwordHash = new XenForo_PasswordHash(XenForo_Application::getConfig()->passwordIterations, false);
  101. $expectedIterations = min(intval(XenForo_Application::getConfig()->passwordIterations), 30);
  102. $iterations = null;
  103.  
  104. if (preg_match('/^\$(P|H)\$(.)/i', $this->_data['hash'], $match))
  105. {
  106. $iterations = $passwordHash->reverseItoA64($match[2]) - 5; // 5 iterations removed in PHP 5
  107. }
  108. else if (preg_match('/^\$2a\$(\d+)\$.*$/i', $this->_data['hash'], $match))
  109. {
  110. $iterations = intval($match[1]);
  111. }
  112.  
  113. return $expectedIterations !== $iterations;
  114. }
  115.  
  116. return true;
  117. }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement