PageRenderTime 53ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/phpBB/includes/ucp/ucp_remind.php

http://github.com/phpbb/phpbb3
PHP | 135 lines | 85 code | 27 blank | 23 comment | 11 complexity | 0d01230062df1b0eccf8eb72da2df7b2 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * This file is part of the phpBB Forum Software package.
  5. *
  6. * @copyright (c) phpBB Limited <https://www.phpbb.com>
  7. * @license GNU General Public License, version 2 (GPL-2.0)
  8. *
  9. * For full copyright and license information, please see
  10. * the docs/CREDITS.txt file.
  11. *
  12. */
  13. /**
  14. * @ignore
  15. */
  16. if (!defined('IN_PHPBB'))
  17. {
  18. exit;
  19. }
  20. /**
  21. * ucp_remind
  22. * Sending password reminders
  23. */
  24. class ucp_remind
  25. {
  26. var $u_action;
  27. function main($id, $mode)
  28. {
  29. global $config, $phpbb_root_path, $phpEx;
  30. global $db, $user, $auth, $template, $phpbb_container;
  31. if (!$config['allow_password_reset'])
  32. {
  33. trigger_error($user->lang('UCP_PASSWORD_RESET_DISABLED', '<a href="mailto:' . htmlspecialchars($config['board_contact']) . '">', '</a>'));
  34. }
  35. $username = request_var('username', '', true);
  36. $email = strtolower(request_var('email', ''));
  37. $submit = (isset($_POST['submit'])) ? true : false;
  38. if ($submit)
  39. {
  40. $sql = 'SELECT user_id, username, user_permissions, user_email, user_jabber, user_notify_type, user_type, user_lang, user_inactive_reason
  41. FROM ' . USERS_TABLE . "
  42. WHERE user_email_hash = '" . $db->sql_escape(phpbb_email_hash($email)) . "'
  43. AND username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
  44. $result = $db->sql_query($sql);
  45. $user_row = $db->sql_fetchrow($result);
  46. $db->sql_freeresult($result);
  47. if (!$user_row)
  48. {
  49. trigger_error('NO_EMAIL_USER');
  50. }
  51. if ($user_row['user_type'] == USER_IGNORE)
  52. {
  53. trigger_error('NO_USER');
  54. }
  55. if ($user_row['user_type'] == USER_INACTIVE)
  56. {
  57. if ($user_row['user_inactive_reason'] == INACTIVE_MANUAL)
  58. {
  59. trigger_error('ACCOUNT_DEACTIVATED');
  60. }
  61. else
  62. {
  63. trigger_error('ACCOUNT_NOT_ACTIVATED');
  64. }
  65. }
  66. // Check users permissions
  67. $auth2 = new \phpbb\auth\auth();
  68. $auth2->acl($user_row);
  69. if (!$auth2->acl_get('u_chgpasswd'))
  70. {
  71. trigger_error('NO_AUTH_PASSWORD_REMINDER');
  72. }
  73. $server_url = generate_board_url();
  74. // Make password at least 8 characters long, make it longer if admin wants to.
  75. // gen_rand_string() however has a limit of 12 or 13.
  76. $user_password = gen_rand_string_friendly(max(8, mt_rand((int) $config['min_pass_chars'], (int) $config['max_pass_chars'])));
  77. // For the activation key a random length between 6 and 10 will do.
  78. $user_actkey = gen_rand_string(mt_rand(6, 10));
  79. // Instantiate passwords manager
  80. $passwords_manager = $phpbb_container->get('passwords.manager');
  81. $sql = 'UPDATE ' . USERS_TABLE . "
  82. SET user_newpasswd = '" . $db->sql_escape($passwords_manager->hash($user_password)) . "', user_actkey = '" . $db->sql_escape($user_actkey) . "'
  83. WHERE user_id = " . $user_row['user_id'];
  84. $db->sql_query($sql);
  85. include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
  86. $messenger = new messenger(false);
  87. $messenger->template('user_activate_passwd', $user_row['user_lang']);
  88. $messenger->set_addresses($user_row);
  89. $messenger->anti_abuse_headers($config, $user);
  90. $messenger->assign_vars(array(
  91. 'USERNAME' => htmlspecialchars_decode($user_row['username']),
  92. 'PASSWORD' => htmlspecialchars_decode($user_password),
  93. 'U_ACTIVATE' => "$server_url/ucp.$phpEx?mode=activate&u={$user_row['user_id']}&k=$user_actkey")
  94. );
  95. $messenger->send($user_row['user_notify_type']);
  96. meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
  97. $message = $user->lang['PASSWORD_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
  98. trigger_error($message);
  99. }
  100. $template->assign_vars(array(
  101. 'USERNAME' => $username,
  102. 'EMAIL' => $email,
  103. 'S_PROFILE_ACTION' => append_sid($phpbb_root_path . 'ucp.' . $phpEx, 'mode=sendpassword'))
  104. );
  105. $this->tpl_name = 'ucp_remind';
  106. $this->page_title = 'UCP_REMIND';
  107. }
  108. }