{"record":{"id":"358f1a2dc6074cbf","repo":"moodle/moodle","slug":"errorpasswordupdate-lib","errorCode":null,"errorMessage":"errorpasswordupdate","messagePattern":"errorpasswordupdate","errorType":"exception","errorClass":"moodle_exception","httpStatus":null,"severity":"error","filePath":"public/login/lib.php","lineNumber":293,"sourceCode":"        // 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;\n        $mform->set_data($setdata);\n        echo $OUTPUT->header();\n        echo $OUTPUT->box(get_string('setpasswordinstructions'), 'generalbox boxwidthnormal boxaligncenter');\n        $mform->display();\n        echo $OUTPUT->footer();\n        return;\n    } else {\n        // User has submitted form.\n        // Delete this token so it can't be used again.\n        $DB->delete_records('user_password_resets', array('id' => $user->tokenid));\n        $userauth = \\core\\di::get(\\core\\authentication::class)->get_plugin($user->auth);\n        if (!$userauth->user_update_password($user, $data->password)) {\n            throw new \\moodle_exception('errorpasswordupdate', 'auth');\n        }\n        \\core\\user::add_password_history($user->id, $data->password);\n        if (!empty($CFG->passwordchangelogout) || !empty($data->logoutothersessions)) {\n            \\core\\session\\manager::destroy_user_sessions($user->id, session_id());\n        }\n        // Reset login lockout (if present) before a new password is set.\n        login_unlock_account($user);\n        // Clear any requirement to change passwords.\n        unset_user_preference('auth_forcepasswordchange', $user);\n        unset_user_preference('create_password', $user);\n\n        if (!empty($user->lang)) {\n            // Unset previous session language - use user preference instead.\n            unset($SESSION->lang);\n        }\n        complete_user_login($user); // Triggers the login event.\n\n        \\core\\session\\manager::apply_concurrent_login_limit($user->id, session_id());","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/moodle/moodle/blob/48ea8c33227277e916cdd4079dbecef448b37f2c/public/login/lib.php#L275-L311","documentation":"This \\moodle_exception('errorpasswordupdate', 'auth') is thrown in core_login_process_password_set (public/login/lib.php:293) when the auth plugin's user_update_password($user, $data->password) call returns false after the user submitted the set-password form. The one-use token has already been deleted at this point, so the reset flow aborts with an auth-plugin-level failure. The error string comes from the auth language pack ('auth'), indicating the plugin could not persist the new password.","triggerScenarios":"Specifically: user submits login_set_password_form with a valid token; $DB->delete_records('user_password_resets', ...) succeeds; \\core\\di::get(\\core\\authentication::class)->get_plugin($user->auth)->user_update_password($user, $data->password) returns false - e.g. LDAP bind/write failure, external auth backend unreachable, plugin does not implement password updates, or DB constraint on mdl_user (password column) fails.","commonSituations":"LDAP/external auth plugin configured without write credentials ('binddn' lacking change-password rights); the plugin's user_update_password is a stub returning false (method-not-implemented style); the directory server rejects the password policy (too weak/history); database issue writing the bcrypt hash; auth plugin changed for the user mid-flow so the plugin loaded can't handle updates.","solutions":["Check which auth plugin the user has and its configuration (Site administration > Plugins > Authentication > <plugin>): ensure password changes are supported (e.g. LDAP 'binddn' with write permission, or switch the user to 'manual' auth).","Enable debugging and the auth plugin's own logs to see the backend error returned by user_update_password (LDAP error code, DB exception).","If the plugin cannot change passwords, an admin sets the password via the user edit page or CLI: php admin/cli/reset_password.php, using an auth plugin that supports it.","Note the reset token was already consumed - after fixing the plugin, have the user request a new reset link from login/forgot_password.php.","Verify the mdl_user table schema/password column is writable (no read-only replica or trigger blocking the UPDATE)."],"exampleFix":"// before: LDAP auth plugin without write bind configured\n$CFG->auth = 'ldap'; // ldap_binddn has read-only rights -> user_update_password() returns false\n// after: either grant the binddn write rights, or move user to manual auth\nUPDATE mdl_user SET auth = 'manual' WHERE username = 'jane';","handlingStrategy":"try-catch","validationCode":"// Verify the auth plugin can actually update passwords before entering the flow\n$authplugin = \\core\\di::get(\\core\\authentication::class)->get_plugin($user->auth);\nif (!method_exists($authplugin, 'user_update_password') || !$authplugin->can_reset_password()) {\n    // password changes unsupported for this user's auth method; use admin reset instead\n}","typeGuard":null,"tryCatchPattern":"try {\n    core_login_process_password_set($token);\n} catch (\\moodle_exception $e) {\n    if ($e->errorcode === 'errorpasswordupdate') {\n        debugging('Auth plugin failed to update password: ' . $e->debuginfo, DEBUG_DEVELOPER);\n        // send the user back to forgot_password.php for a fresh token after the plugin is fixed\n        redirect($CFG->wwwroot . '/login/forgot_password.php');\n    }\n}","preventionTips":["Give external-auth bind accounts (LDAP/AD) write rights if self-service password change is intended.","Confirm the auth plugin implements user_update_password (not a stub) before advertising self-service resets.","Test password policy compliance against the external directory to avoid backend rejections.","Keep auth plugins updated; verify with a test user after Moodle upgrades.","Watch for partially consumed tokens: the token is deleted before the update, so failures require a fresh reset request."],"tags":["moodle","auth-plugin","password-update","ldap"],"backgroundTag":"database-write-failed","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"}