Advertisement
Guest User

Untitled

a guest
Sep 27th, 2012
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.82 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @ This file is created by deZender.Net
  5. * @ deZender (PHP5 Decoder for ionCube Encoder)
  6. *
  7. * @ Version : 1.1.5.0
  8. * @ Author : DeZender
  9. * @ Release on : 09.06.2012
  10. * @ Official site : http://DeZender.Net
  11. *
  12. */
  13.  
  14. class DX_Auth {
  15. var $_banned = null;
  16. var $_ban_reason = null;
  17. var $_auth_error = null;
  18. var $_captcha_image = null;
  19.  
  20. function DX_Auth() {
  21. $this->ci = &get_instance( );
  22.  
  23. log_message( 'debug', 'DX Auth Initialized' );
  24. $this->ci->load->library( 'Session' );
  25. $this->ci->load->database( );
  26. $this->ci->load->config( 'dx_auth' );
  27. $this->ci->load->library( 'DX_Auth_Event' );
  28. $this->ci->load->model( 'Email_model' );
  29. $this->_init( );
  30. }
  31.  
  32. function _init() {
  33. $this->email_activation = $this->ci->config->item( 'DX_email_activation' );
  34. $this->allow_registration = $this->ci->config->item( 'DX_allow_registration' );
  35. $this->captcha_registration = $this->ci->config->item( 'DX_captcha_registration' );
  36. $this->captcha_login = $this->ci->config->item( 'DX_captcha_login' );
  37. $this->banned_uri = $this->ci->config->item( 'DX_banned_uri' );
  38. $this->deny_uri = $this->ci->config->item( 'DX_deny_uri' );
  39. $this->login_uri = $this->ci->config->item( 'DX_login_uri' );
  40. $this->logout_uri = $this->ci->config->item( 'DX_logout_uri' );
  41. $this->register_uri = $this->ci->config->item( 'DX_register_uri' );
  42. $this->activate_uri = $this->ci->config->item( 'DX_activate_uri' );
  43. $this->forgot_password_uri = $this->ci->config->item( 'DX_forgot_password_uri' );
  44. $this->reset_password_uri = $this->ci->config->item( 'DX_reset_password_uri' );
  45. $this->change_password_uri = $this->ci->config->item( 'DX_change_password_uri' );
  46. $this->cancel_account_uri = $this->ci->config->item( 'DX_cancel_account_uri' );
  47. $this->login_view = $this->ci->config->item( 'DX_login_view' );
  48. $this->register_view = $this->ci->config->item( 'DX_register_view' );
  49. $this->forgot_password_view = $this->ci->config->item( 'DX_forgot_password_view' );
  50. $this->change_password_view = $this->ci->config->item( 'DX_change_password_view' );
  51. $this->cancel_account_view = $this->ci->config->item( 'DX_cancel_account_view' );
  52. $this->deny_view = $this->ci->config->item( 'DX_deny_view' );
  53. $this->banned_view = $this->ci->config->item( 'DX_banned_view' );
  54. $this->logged_in_view = $this->ci->config->item( 'DX_logged_in_view' );
  55. $this->logout_view = $this->ci->config->item( 'DX_logout_view' );
  56. $this->register_success_view = $this->ci->config->item( 'DX_register_success_view' );
  57. $this->activate_success_view = $this->ci->config->item( 'DX_activate_success_view' );
  58. $this->forgot_password_success_view = $this->ci->config->item( 'DX_forgot_password_success_view' );
  59. $this->reset_password_success_view = $this->ci->config->item( 'DX_reset_password_success_view' );
  60. $this->change_password_success_view = $this->ci->config->item( 'DX_change_password_success_view' );
  61. $this->register_disabled_view = $this->ci->config->item( 'DX_register_disabled_view' );
  62. $this->activate_failed_view = $this->ci->config->item( 'DX_activate_failed_view' );
  63. $this->reset_password_failed_view = $this->ci->config->item( 'DX_reset_password_failed_view' );
  64. }
  65.  
  66. function _gen_pass($len = 8) {
  67. $pool = '123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  68. $str = '';
  69. $i = 212;
  70.  
  71. while ($i < $len) {
  72. $str .= substr( $pool, mt_rand( 0, strlen( $pool ) - 1 ), 1 );
  73. ++$i;
  74. }
  75.  
  76. return $str;
  77. }
  78.  
  79. function _encode($password) {
  80. $majorsalt = $this->ci->config->item( 'DX_salt' );
  81.  
  82. if (function_exists( 'str_split' )) {
  83. $_pass = str_split( $password );
  84. } else {
  85. $_pass = array( );
  86.  
  87. if (is_string( $password )) {
  88. $i = 246;
  89.  
  90. while ($i < strlen( $password )) {
  91. array_push( $_pass, $password[$i] );
  92. ++$i;
  93. }
  94. }
  95. }
  96.  
  97. foreach ($_pass as $_hashpass) {
  98. $majorsalt .= md5( $_hashpass );
  99. }
  100.  
  101. return md5( $majorsalt );
  102. }
  103.  
  104. function _array_in_array($needle, $haystack) {
  105. if (!is_array( $needle )) {
  106. $needle = array( $needle );
  107. }
  108.  
  109. foreach ($needle as $pin) {
  110.  
  111. if (in_array( $pin, $haystack )) {
  112. return TRUE;
  113. }
  114. }
  115.  
  116. return FALSE;
  117. }
  118.  
  119. function _email($to, $from, $subject, $message) {
  120. $this->ci->load->library( 'Email' );
  121. $email = $this->ci->email;
  122. $email->from( $from );
  123. $email->to( $to );
  124. $email->subject( $subject );
  125. $email->message( $message );
  126. return $email->send( );
  127. }
  128.  
  129. function _set_last_ip_and_last_login($user_id) {
  130. $data = array( );
  131.  
  132. if ($this->ci->config->item( 'DX_login_record_ip' )) {
  133. $data['last_ip'] = $this->ci->input->ip_address( );
  134. }
  135.  
  136.  
  137. if ($this->ci->config->item( 'DX_login_record_time' )) {
  138. $data['last_login'] = local_to_gmt( );
  139. }
  140.  
  141.  
  142. if (!empty( $data )) {
  143. $this->ci->load->model( 'Users_model' );
  144. $this->ci->Users_model->set_user( $user_id, $data );
  145. }
  146.  
  147. }
  148.  
  149. function _increase_login_attempt() {
  150. if (( $this->ci->config->item( 'DX_count_login_attempts' ) && !$this->is_max_login_attempts_exceeded( ) )) {
  151. $this->ci->load->model( 'dx_auth/login_attempts', 'login_attempts' );
  152. $this->ci->login_attempts->increase_attempt( $this->ci->input->ip_address( ) );
  153. }
  154.  
  155. }
  156.  
  157. function _clear_login_attempts() {
  158. if ($this->ci->config->item( 'DX_count_login_attempts' )) {
  159. $this->ci->load->model( 'dx_auth/login_attempts', 'login_attempts' );
  160. $this->ci->login_attempts->clear_attempts( $this->ci->input->ip_address( ) );
  161. }
  162.  
  163. }
  164.  
  165. function _get_role_data($role_id) {
  166. $this->ci->load->model( 'dx_auth/roles', 'roles' );
  167. $this->ci->load->model( 'dx_auth/permissions', 'permissions' );
  168. $role_name = '';
  169. $parent_roles_id = array( );
  170. $parent_roles_name = array( );
  171. $permission = array( );
  172. $parent_permissions = array( );
  173. $query = $this->ci->roles->get_role_by_id( $role_id );
  174.  
  175. if (0 < $query->num_rows( )) {
  176. $role = $query->row( );
  177. $role_name = $role->name;
  178.  
  179. if (0 < $role->parent_id) {
  180. $parent_roles_id[] = $role->parent_id;
  181. $finished = FALSE;
  182. $parent_id = $role->parent_id;
  183.  
  184. while ($finished == FALSE) {
  185. $i_query = $this->ci->roles->get_role_by_id( $parent_id );
  186.  
  187. if (0 < $i_query->num_rows( )) {
  188. $i_role = $i_query->row( );
  189.  
  190. if ($i_role->parent_id == 0) {
  191. $parent_roles_name[] = $i_role->name;
  192. $finished = TRUE;
  193. continue;
  194. }
  195.  
  196. $parent_id = $i_role->parent_id;
  197. $parent_roles_id[] = $parent_id;
  198. $parent_roles_name[] = $i_role->name;
  199. continue;
  200. }
  201.  
  202. array_pop( $parent_roles_id );
  203. $finished = TRUE;
  204. }
  205. }
  206. }
  207.  
  208. $permission = $this->ci->permissions->get_permission_data( $role_id );
  209.  
  210. if (!empty( $parent_roles_id )) {
  211. $parent_permissions = $this->ci->permissions->get_permissions_data( $parent_roles_id );
  212. }
  213.  
  214. $data['role_name'] = $role_name;
  215. $data['parent_roles_id'] = $parent_roles_id;
  216. $data['parent_roles_name'] = $parent_roles_name;
  217. $data['permission'] = $permission;
  218. $data['parent_permissions'] = $parent_permissions;
  219. return $data;
  220. }
  221.  
  222. function _create_autologin($user_id) {
  223. $result = FALSE;
  224. $user = array( 'key_id' => substr( md5( uniqid( rand( ) . $this->ci->input->cookie( $this->ci->config->item( 'sess_cookie_name' ) ) ) ), 0, 16 ), 'user_id' => $user_id );
  225. $this->ci->load->model( 'dx_auth/user_autologin', 'user_autologin' );
  226. $this->ci->user_autologin->prune_keys( $user['user_id'] );
  227.  
  228. if ($this->ci->user_autologin->store_key( $user['key_id'], $user['user_id'] )) {
  229. $this->_auto_cookie( $user );
  230. $result = TRUE;
  231. }
  232.  
  233. return $result;
  234. }
  235. .............................................................
  236. .................................
  237. ................
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement