/** * Generate and set a new password for a specific user not in session. * * @param integer $user_id The user identifier that will be changed, this must be different than the user in session. * @return boolean Either TRUE or FALSE in case of success or error respectively. */ public static function set_new_password($user_id = 0) { $user_id = intval($user_id); if ($user_id > 0 && function_exists('wp_generate_password')) { $user = get_userdata($user_id); if ($user instanceof WP_User) { $website = SucuriScan::get_domain(); $user_login = $user->user_login; $display_name = $user->display_name; $new_password = wp_generate_password(15, true, false); $message = SucuriScanTemplate::get_section('notification-resetpwd', array('ResetPassword.UserName' => $user_login, 'ResetPassword.DisplayName' => $display_name, 'ResetPassword.Password' => $new_password, 'ResetPassword.Website' => $website)); $data_set = array('Force' => true); // Skip limit for emails per hour. SucuriScanMail::send_mail($user->user_email, 'Password changed', $message, $data_set); wp_set_password($new_password, $user_id); return true; } } return false; }
/** * Generate and set a new password for a specific user not in session. * * @param integer $user_id The user identifier that will be changed, this must be different than the user in session. * @return boolean Either TRUE or FALSE in case of success or error respectively. */ public static function set_new_password($user_id = 0) { $user_id = intval($user_id); if ($user_id > 0 && function_exists('wp_generate_password')) { $user = get_userdata($user_id); if ($user instanceof WP_User) { $new_password = wp_generate_password(15, true, false); $message = 'The password for your user account <strong>"' . $user->display_name . '"</strong> ' . 'in the website specified above was changed, this is the new password generated automatically ' . 'by the system, please update as soon as possible.<br><div style="display:inline-block;' . 'background:#ddd;font-family:monaco,monospace,courier;font-size:30px;margin:0;padding:15px;' . 'border:1px solid #999">' . $new_password . '</div>'; $data_set = array('Force' => true); // Skip limit for emails per hour. SucuriScanMail::send_mail($user->user_email, 'Password changed', $message, $data_set); wp_set_password($new_password, $user_id); return true; } } return false; }