public static function resend_confirmation_email($username, $password, $redirect = '') {
        global $PAGE;

        $warnings = array();
        $params = self::validate_parameters(
            self::resend_confirmation_email_parameters(),
            array(
                'username' => $username,
                'password' => $password,
                'redirect' => $redirect,
            )
        );

        $context = context_system::instance();
        $PAGE->set_context($context);   // Need by internal APIs.
        $username = trim(core_text::strtolower($params['username']));
        $password = $params['password'];

        if (is_restored_user($username)) {
            throw new moodle_exception('restoredaccountresetpassword', 'webservice');
        }

        $user = authenticate_user_login($username, $password);

        if (empty($user)) {
            throw new moodle_exception('invalidlogin');
        }

        if ($user->confirmed) {
            throw new moodle_exception('alreadyconfirmed');
        }

        // Check if we should redirect the user once the user is confirmed.
        $confirmationurl = null;
        if (!empty($params['redirect'])) {
            // Pass via moodle_url to fix thinks like admin links.
            $redirect = new moodle_url($params['redirect']);

            $confirmationurl = new moodle_url('/login/confirm.php', array('redirect' => $redirect->out()));
        }
        $status = send_confirmation_email($user, $confirmationurl);

        return array(
            'status' => $status,
            'warnings' => $warnings,
        );
    }