PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/diendan/login.php

http://xoxoshop2010.googlecode.com/
PHP | 265 lines | 187 code | 39 blank | 39 comment | 62 complexity | a14e8a9901ba7638cb4aa588dc209928 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /***************************************************************************
  3. * login.php
  4. * -------------------
  5. * begin : Saturday, Feb 13, 2001
  6. * copyright : (C) 2001 The phpBB Group
  7. * email : support@phpbb.com
  8. *
  9. * $Id: login.php,v 1.47.2.25 2006/12/16 13:11:24 acydburn Exp $
  10. *
  11. *
  12. ***************************************************************************/
  13. /***************************************************************************
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or
  18. * (at your option) any later version.
  19. *
  20. ***************************************************************************/
  21. //
  22. // Allow people to reach login page if
  23. // board is shut down
  24. //
  25. define("IN_LOGIN", true);
  26. define('IN_PHPBB', true);
  27. $phpbb_root_path = './';
  28. include($phpbb_root_path . 'extension.inc');
  29. include($phpbb_root_path . 'common.'.$phpEx);
  30. //
  31. // Set page ID for session management
  32. //
  33. $userdata = session_pagestart($user_ip, PAGE_LOGIN);
  34. init_userprefs($userdata);
  35. //
  36. // End session management
  37. //
  38. // session id check
  39. if (!empty($HTTP_POST_VARS['sid']) || !empty($HTTP_GET_VARS['sid']))
  40. {
  41. $sid = (!empty($HTTP_POST_VARS['sid'])) ? $HTTP_POST_VARS['sid'] : $HTTP_GET_VARS['sid'];
  42. }
  43. else
  44. {
  45. $sid = '';
  46. }
  47. if( isset($HTTP_POST_VARS['login']) || isset($HTTP_GET_VARS['login']) || isset($HTTP_POST_VARS['logout']) || isset($HTTP_GET_VARS['logout']) )
  48. {
  49. if( ( isset($HTTP_POST_VARS['login']) || isset($HTTP_GET_VARS['login']) ) && (!$userdata['session_logged_in'] || isset($HTTP_POST_VARS['admin'])) )
  50. {
  51. $username = isset($HTTP_POST_VARS['username']) ? phpbb_clean_username($HTTP_POST_VARS['username']) : '';
  52. $password = isset($HTTP_POST_VARS['password']) ? $HTTP_POST_VARS['password'] : '';
  53. $sql = "SELECT user_id, username, user_password, user_active, user_level, user_login_tries, user_last_login_try
  54. FROM " . USERS_TABLE . "
  55. WHERE username = '" . str_replace("\\'", "''", $username) . "'";
  56. if ( !($result = $db->sql_query($sql)) )
  57. {
  58. message_die(GENERAL_ERROR, 'Error in obtaining userdata', '', __LINE__, __FILE__, $sql);
  59. }
  60. if( $row = $db->sql_fetchrow($result) )
  61. {
  62. if( $row['user_level'] != ADMIN && $board_config['board_disable'] )
  63. {
  64. redirect(append_sid("index.$phpEx", true));
  65. }
  66. else
  67. {
  68. // If the last login is more than x minutes ago, then reset the login tries/time
  69. if ($row['user_last_login_try'] && $board_config['login_reset_time'] && $row['user_last_login_try'] < (time() - ($board_config['login_reset_time'] * 60)))
  70. {
  71. $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_login_tries = 0, user_last_login_try = 0 WHERE user_id = ' . $row['user_id']);
  72. $row['user_last_login_try'] = $row['user_login_tries'] = 0;
  73. }
  74. // Check to see if user is allowed to login again... if his tries are exceeded
  75. if ($row['user_last_login_try'] && $board_config['login_reset_time'] && $board_config['max_login_attempts'] &&
  76. $row['user_last_login_try'] >= (time() - ($board_config['login_reset_time'] * 60)) && $row['user_login_tries'] >= $board_config['max_login_attempts'] && $userdata['user_level'] != ADMIN)
  77. {
  78. message_die(GENERAL_MESSAGE, sprintf($lang['Login_attempts_exceeded'], $board_config['max_login_attempts'], $board_config['login_reset_time']));
  79. }
  80. if( md5($password) == $row['user_password'] && $row['user_active'] )
  81. {
  82. $autologin = ( isset($HTTP_POST_VARS['autologin']) ) ? TRUE : 0;
  83. $admin = (isset($HTTP_POST_VARS['admin'])) ? 1 : 0;
  84. $session_id = session_begin($row['user_id'], $user_ip, PAGE_INDEX, FALSE, $autologin, $admin);
  85. // Reset login tries
  86. $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_login_tries = 0, user_last_login_try = 0 WHERE user_id = ' . $row['user_id']);
  87. if( $session_id )
  88. {
  89. $url = ( !empty($HTTP_POST_VARS['redirect']) ) ? str_replace('&amp;', '&', htmlspecialchars($HTTP_POST_VARS['redirect'])) : "index.$phpEx";
  90. redirect(append_sid($url, true));
  91. }
  92. else
  93. {
  94. message_die(CRITICAL_ERROR, "Couldn't start session : login", "", __LINE__, __FILE__);
  95. }
  96. }
  97. // Only store a failed login attempt for an active user - inactive users can't login even with a correct password
  98. elseif( $row['user_active'] )
  99. {
  100. // Save login tries and last login
  101. if ($row['user_id'] != ANONYMOUS)
  102. {
  103. $sql = 'UPDATE ' . USERS_TABLE . '
  104. SET user_login_tries = user_login_tries + 1, user_last_login_try = ' . time() . '
  105. WHERE user_id = ' . $row['user_id'];
  106. $db->sql_query($sql);
  107. }
  108. }
  109. $redirect = ( !empty($HTTP_POST_VARS['redirect']) ) ? str_replace('&amp;', '&', htmlspecialchars($HTTP_POST_VARS['redirect'])) : '';
  110. $redirect = str_replace('?', '&', $redirect);
  111. if (strstr(urldecode($redirect), "\n") || strstr(urldecode($redirect), "\r") || strstr(urldecode($redirect), ';url'))
  112. {
  113. message_die(GENERAL_ERROR, 'Tried to redirect to potentially insecure url.');
  114. }
  115. $template->assign_vars(array(
  116. 'META' => "<meta http-equiv=\"refresh\" content=\"3;url=login.$phpEx?redirect=$redirect\">")
  117. );
  118. $message = $lang['Error_login'] . '<br /><br />' . sprintf($lang['Click_return_login'], "<a href=\"login.$phpEx?redirect=$redirect\">", '</a>') . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a>');
  119. message_die(GENERAL_MESSAGE, $message);
  120. }
  121. }
  122. else
  123. {
  124. $redirect = ( !empty($HTTP_POST_VARS['redirect']) ) ? str_replace('&amp;', '&', htmlspecialchars($HTTP_POST_VARS['redirect'])) : "";
  125. $redirect = str_replace("?", "&", $redirect);
  126. if (strstr(urldecode($redirect), "\n") || strstr(urldecode($redirect), "\r") || strstr(urldecode($redirect), ';url'))
  127. {
  128. message_die(GENERAL_ERROR, 'Tried to redirect to potentially insecure url.');
  129. }
  130. $template->assign_vars(array(
  131. 'META' => "<meta http-equiv=\"refresh\" content=\"3;url=login.$phpEx?redirect=$redirect\">")
  132. );
  133. $message = $lang['Error_login'] . '<br /><br />' . sprintf($lang['Click_return_login'], "<a href=\"login.$phpEx?redirect=$redirect\">", '</a>') . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a>');
  134. message_die(GENERAL_MESSAGE, $message);
  135. }
  136. }
  137. else if( ( isset($HTTP_GET_VARS['logout']) || isset($HTTP_POST_VARS['logout']) ) && $userdata['session_logged_in'] )
  138. {
  139. // session id check
  140. if ($sid == '' || $sid != $userdata['session_id'])
  141. {
  142. message_die(GENERAL_ERROR, 'Invalid_session');
  143. }
  144. if( $userdata['session_logged_in'] )
  145. {
  146. session_end($userdata['session_id'], $userdata['user_id']);
  147. }
  148. if (!empty($HTTP_POST_VARS['redirect']) || !empty($HTTP_GET_VARS['redirect']))
  149. {
  150. $url = (!empty($HTTP_POST_VARS['redirect'])) ? htmlspecialchars($HTTP_POST_VARS['redirect']) : htmlspecialchars($HTTP_GET_VARS['redirect']);
  151. $url = str_replace('&amp;', '&', $url);
  152. redirect(append_sid($url, true));
  153. }
  154. else
  155. {
  156. redirect(append_sid("index.$phpEx", true));
  157. }
  158. }
  159. else
  160. {
  161. $url = ( !empty($HTTP_POST_VARS['redirect']) ) ? str_replace('&amp;', '&', htmlspecialchars($HTTP_POST_VARS['redirect'])) : "index.$phpEx";
  162. redirect(append_sid($url, true));
  163. }
  164. }
  165. else
  166. {
  167. //
  168. // Do a full login page dohickey if
  169. // user not already logged in
  170. //
  171. if( !$userdata['session_logged_in'] || (isset($HTTP_GET_VARS['admin']) && $userdata['session_logged_in'] && $userdata['user_level'] == ADMIN))
  172. {
  173. $page_title = $lang['Login'];
  174. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  175. $template->set_filenames(array(
  176. 'body' => 'login_body.tpl')
  177. );
  178. $forward_page = '';
  179. if( isset($HTTP_POST_VARS['redirect']) || isset($HTTP_GET_VARS['redirect']) )
  180. {
  181. $forward_to = $HTTP_SERVER_VARS['QUERY_STRING'];
  182. if( preg_match("/^redirect=([a-z0-9\.#\/\?&=\+\-_]+)/si", $forward_to, $forward_matches) )
  183. {
  184. $forward_to = ( !empty($forward_matches[3]) ) ? $forward_matches[3] : $forward_matches[1];
  185. $forward_match = explode('&', $forward_to);
  186. if(count($forward_match) > 1)
  187. {
  188. for($i = 1; $i < count($forward_match); $i++)
  189. {
  190. if( !ereg("sid=", $forward_match[$i]) )
  191. {
  192. if( $forward_page != '' )
  193. {
  194. $forward_page .= '&';
  195. }
  196. $forward_page .= $forward_match[$i];
  197. }
  198. }
  199. $forward_page = $forward_match[0] . '?' . $forward_page;
  200. }
  201. else
  202. {
  203. $forward_page = $forward_match[0];
  204. }
  205. }
  206. }
  207. $username = ( $userdata['user_id'] != ANONYMOUS ) ? $userdata['username'] : '';
  208. $s_hidden_fields = '<input type="hidden" name="redirect" value="' . $forward_page . '" />';
  209. $s_hidden_fields .= (isset($HTTP_GET_VARS['admin'])) ? '<input type="hidden" name="admin" value="1" />' : '';
  210. make_jumpbox('viewforum.'.$phpEx);
  211. $template->assign_vars(array(
  212. 'USERNAME' => $username,
  213. 'L_ENTER_PASSWORD' => (isset($HTTP_GET_VARS['admin'])) ? $lang['Admin_reauthenticate'] : $lang['Enter_password'],
  214. 'L_SEND_PASSWORD' => $lang['Forgotten_password'],
  215. 'U_SEND_PASSWORD' => append_sid("profile.$phpEx?mode=sendpassword"),
  216. 'S_HIDDEN_FIELDS' => $s_hidden_fields)
  217. );
  218. $template->pparse('body');
  219. include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
  220. }
  221. else
  222. {
  223. redirect(append_sid("index.$phpEx", true));
  224. }
  225. }
  226. ?>