# Design ## Context - **Emailed reset:** `POST /api/admin/users/{id}/resetPassword` (mobile-api, `@AdminModule("BO_USERS")`) runs `AdminUserService.resetPassword`. That loads the target with `loadManaged`, which refuses a super admin to a non-super caller, then calls services-system `/user/resetAdminPassword`. That endpoint: - checks the user is type `A`, enabled, and that the email matches; - generates `ValidateUtil.getRandomPasswordString(8)`; - stores it bcrypt-encoded with `login = N`; - emails it. - **Generator:** `getRandomPasswordString` uses `java.util.Random` over an alphabet without look-alike characters. - **Sign-in:** `login = N` makes mobile-api answer every admin call with 403 `PASSWORD_RESET_REQUIRED` until `/api/admin/auth/first-login`. The portal redirects to the change-password page on that code. - **Logging:** the gateway logs no bodies (spec `gateway-request-logging`). ## Goals / Non-Goals **Goals:** onboard and unlock staff without email; make every generated temporary password unpredictable. **Non-Goals:** admin-chosen passwords; ending the user's existing sessions on reset (the emailed reset does not do this today either); a create-form option. ## Decisions 1. **SecureRandom at the shared generator.** `getRandomPasswordString` draws from one static `SecureRandom` with `nextInt(alphabet.length())`, keeping the same alphabet. This one change covers every caller: the emailed reset, forgot-password, user creation and the new path. 2. **services-system endpoint `POST /user/issueAdminTempPassword`** with body `{id}`: - It refuses (returns no password) unless the user exists, is type `A` and is enabled. - It generates 12 characters, stores them bcrypt-encoded with `login = N`, and returns `{"password": ""}`. - It sends no email. - It sits beside `resetAdminPassword` and is reachable only inside the cluster, through the gateway (`/user/**` route). - Alternative: add a "don't email" flag to `resetAdminPassword`. Rejected: that endpoint also serves the public forgot-password path, and a flag there could be misused. 3. **mobile-api `POST /api/admin/users/{id}/temporary-password`** in `AdminUserController` (class-level `BO_USERS`), via `AdminUserService.issueTemporaryPassword(id)`: - It refuses its own account: 400 `SELF_NOT_ALLOWED`. - It uses `loadManaged`: 404 for an unknown user, and 403 for a super admin when the caller is not one. - It refuses a disabled user: 409 `USER_DISABLED`. - On success it returns `{"password": "..."}` with `Cache-Control: no-store`. - It logs only the audit line `temporary password set by for user `, never the password. 4. **Portal:** - A "Set temporary password" button on `/users/[id]`, beside the existing reset button. - It opens a confirmation first, then calls a new proxy route that forwards `Cache-Control: no-store`. - On success it shows a dialog with the password, a copy button, and the note "Shown once. The user must change it at first sign-in". - The password lives only in that dialog's React state and is cleared when the dialog closes. It never goes into the URL, storage or logs. - Refusals show their message on the page. 5. **Handover:** `docs/deployment.md` section 10 says staff can be onboarded without email through this action. ## Risks / Trade-offs - [The admin knows the temporary password] → It is single-use in practice: the user must change it at first sign-in before any other call works. That is the same exposure as an emailed reset, minus the mailbox. - [Existing sessions of the user survive the reset] → Same as the emailed reset today. Recorded as a follow-up with the existing "refreshed token stays valid" item. - [Clipboard access needs HTTPS] → Production is HTTPS. If the copy fails, the password stays visible and selectable. ## Migration Plan No data change. Deploy services-system, mobile-api and the portal; the core-libs change ships inside each service jar. Rollback is the previous images.