feat: admin-set passwords for staff, and a secure temporary-password generator

Creating a user takes the first password from the admin, and a new
POST /api/admin/users/{id}/password lets an admin set a temporary password
for another active user. Both store the bcrypt hash with login = N, so the
user must choose their own password at the next sign-in. No email is sent.
The password must match its confirmation and pass the admin password rules.
The emailed-password generator now draws from SecureRandom.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-11-30 11:19:10 +08:00
1 parent b49c9f1bc3
commit 2c0a847b68
12 files changed
+386 -15

No files matched your search

@@ -105,4 +105,12 @@ class AdminUserControllerTest {
.andExpect(status().is4xxClientError());
org.mockito.Mockito.verifyNoInteractions(users);
}
@Test
void setPassword_passesBothFieldsAndReturns204() throws Exception {
mvc.perform(post("/api/admin/users/5/password").contentType(MediaType.APPLICATION_JSON)
.content("{\"password\":\"Good#Pass1\",\"confirmPassword\":\"Good#Pass1\"}"))
.andExpect(status().isNoContent());
verify(users).setTemporaryPassword(5L, "Good#Pass1", "Good#Pass1");
}
}