moodle/moodle · error · moodle_exception

forgotteninvalidurl

Error message

forgotteninvalidurl

What it means

This \moodle_exception('forgotteninvalidurl') is thrown in core_login_process_password_set (public/login/lib.php:262) when a user arrives with a valid, unexpired password-reset token, but their account cannot be allowed to set a new password because its auth method is 'nologin' or the auth plugin is currently disabled. The header is echoed first, then the exception is thrown to display the 'forgotten password invalid URL' error page. The intent is to block password setting for accounts that cannot log in anyway.

Solutions

  1. Re-enable the user's authentication plugin in Site administration > Plugins > Authentication, or change the user's auth method to an enabled one (e.g. 'manual') if they should log in.
  2. Check the user's account: user record 'auth' field via admin user edit page; fix 'nologin' accounts that should be able to sign in.
  3. Ask the user to request a fresh password-reset link after the auth method is corrected, since the old link's flow will re-run the same check.
  4. If the account is intentionally unable to log in, no code change is needed - the error is the correct behavior; communicate this to the user.

Example fix

// before: user's auth is disabled/nologin
UPDATE mdl_user SET auth = 'manual' WHERE username = 'jane';
// after: auth set to an enabled plugin, then re-request reset
-- (then re-enable 'manual' in Site administration > Plugins > Authentication if disabled)
Defensive patterns

Strategy: validation

Validate before calling

// Validate the token's user before invoking the flow
$user = $DB->get_record_sql("SELECT u.* FROM {user} u JOIN {user_password_resets} upr ON upr.userid = u.id WHERE upr.token = ?", [$token]);
if (!$user || $user->auth === 'nologin' || !\core\di::get(\core\authentication::class)->is_enabled($user->auth)) {
    // refuse early with a friendly message instead of the mid-flow exception
}

Prevention

When it happens

Trigger: Specifically: core_login_process_password_set($token) is called (via forgotten_password.php token link) where the token resolves to a user whose $user->auth === 'nologin', or \core\di::get(\core\authentication::class)->is_enabled($user->auth) returns false (e.g. the admin disabled the LDAP/Moodle auth plugin after the token email was sent).

Common situations: Admin disables an auth plugin while old reset emails are still in circulation; user accounts set to nologin (e.g. imported/SUSPENDED-like accounts, MFA-lock style) request resets beforehand; site migration where auth plugins were not re-enabled; clicking an old reset link after the auth method was switched for the user.

Related errors


AI-assisted analysis of moodle/moodle@48ea8c3322 (2026-09-14). Data as JSON: /api/errors/d6c026ecd3115bb8. Report an issue: GitHub.

Appendix: source

Thrown at public/login/lib.php:262

        notice(get_string('noresetrecord'), $forgotpasswordurl);
        die; // Never reached.
    }
    if ($user->timerequested < (time() - $pwresettime)) {
        // There is a reset record, but it's expired.
        // Direct the user to the forgot password page to request a password reset.
        $pwresetmins = floor($pwresettime / MINSECS);
        echo $OUTPUT->header();
        notice(get_string('resetrecordexpired', '', $pwresetmins), $forgotpasswordurl);
        die; // Never reached.
    }

    if (
        $user->auth === 'nologin'
        || !\core\di::get(\core\authentication::class)->is_enabled($user->auth)
    ) {
        // Bad luck - user is not able to login, do not let them set password.
        echo $OUTPUT->header();
        throw new \moodle_exception('forgotteninvalidurl');
        die; // Never reached.
    }

    // Check this isn't guest user.
    if (isguestuser($user)) {
        throw new \moodle_exception('cannotresetguestpwd');
    }

    // Token is correct, and unexpired.
    $mform = new login_set_password_form(null, $user);
    $data = $mform->get_data();
    if (empty($data)) {
        // User hasn't submitted form, they got here directly from email link.
        // Next, display the form.
        $setdata = new stdClass();
        $setdata->username = $user->username;
        $setdata->username2 = s($user->username);
        $setdata->token = $user->token;

View on GitHub (pinned to 48ea8c3322)