{"record":{"id":"d6c026ecd3115bb8","repo":"moodle/moodle","slug":"forgotteninvalidurl","errorCode":null,"errorMessage":"forgotteninvalidurl","messagePattern":"forgotteninvalidurl","errorType":"exception","errorClass":"moodle_exception","httpStatus":null,"severity":"error","filePath":"public/login/lib.php","lineNumber":262,"sourceCode":"        notice(get_string('noresetrecord'), $forgotpasswordurl);\n        die; // Never reached.\n    }\n    if ($user->timerequested < (time() - $pwresettime)) {\n        // There is a reset record, but it's expired.\n        // Direct the user to the forgot password page to request a password reset.\n        $pwresetmins = floor($pwresettime / MINSECS);\n        echo $OUTPUT->header();\n        notice(get_string('resetrecordexpired', '', $pwresetmins), $forgotpasswordurl);\n        die; // Never reached.\n    }\n\n    if (\n        $user->auth === 'nologin'\n        || !\\core\\di::get(\\core\\authentication::class)->is_enabled($user->auth)\n    ) {\n        // Bad luck - user is not able to login, do not let them set password.\n        echo $OUTPUT->header();\n        throw new \\moodle_exception('forgotteninvalidurl');\n        die; // Never reached.\n    }\n\n    // Check this isn't guest user.\n    if (isguestuser($user)) {\n        throw new \\moodle_exception('cannotresetguestpwd');\n    }\n\n    // Token is correct, and unexpired.\n    $mform = new login_set_password_form(null, $user);\n    $data = $mform->get_data();\n    if (empty($data)) {\n        // User hasn't submitted form, they got here directly from email link.\n        // Next, display the form.\n        $setdata = new stdClass();\n        $setdata->username = $user->username;\n        $setdata->username2 = s($user->username);\n        $setdata->token = $user->token;","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/moodle/moodle/blob/48ea8c33227277e916cdd4079dbecef448b37f2c/public/login/lib.php#L244-L280","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["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.","Check the user's account: user record 'auth' field via admin user edit page; fix 'nologin' accounts that should be able to sign in.","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.","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."],"exampleFix":"// before: user's auth is disabled/nologin\nUPDATE mdl_user SET auth = 'manual' WHERE username = 'jane';\n// after: auth set to an enabled plugin, then re-request reset\n-- (then re-enable 'manual' in Site administration > Plugins > Authentication if disabled)","handlingStrategy":"validation","validationCode":"// Validate the token's user before invoking the flow\n$user = $DB->get_record_sql(\"SELECT u.* FROM {user} u JOIN {user_password_resets} upr ON upr.userid = u.id WHERE upr.token = ?\", [$token]);\nif (!$user || $user->auth === 'nologin' || !\\core\\di::get(\\core\\authentication::class)->is_enabled($user->auth)) {\n    // refuse early with a friendly message instead of the mid-flow exception\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When disabling an auth plugin, first migrate its users to another enabled plugin.","Avoid setting auth='nologin' for accounts that may still request resets; suspend them instead.","Communicate short reset-token lifetimes (CFG->pwresettime) so users redeem links promptly after auth changes.","Audit mdl_user.auth values regularly against enabled plugins."],"tags":["moodle","authentication","password-reset","account-locked"],"backgroundTag":"feature-not-enabled","analyzedSha":"48ea8c33227277e916cdd4079dbecef448b37f2c","analyzedAt":"2026-09-14T20:34:48.527Z","contentChangedAt":"2026-09-14T20:34:48.527Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}