feat(server): add --reset-password admin subcommand
Self-hosters can now run: ./solitaire_server --reset-password <username> to update a player's password and invalidate all their refresh tokens (forcing re-login on every device). Password is read from stdin so it can be piped from scripts or a password manager without appearing in shell history. Implementation: - reset_password() in auth.rs: validates length, bcrypt-hashes new password, updates users.password_hash, deletes all refresh_tokens rows for the user. - main.rs: --reset-password dispatch before HTTP server startup; JWT_SECRET not required for this path. - 4 integration tests covering: login works after reset, old password rejected, refresh tokens invalidated, unknown user → NotFound, short password → BadRequest. - README_SERVER.md: admin password-reset section with examples. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -42,3 +42,29 @@ git pull
|
||||
docker compose build
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
|
||||
## Admin — Password Reset
|
||||
|
||||
If a player loses access to their account, the server binary includes a
|
||||
built-in password reset command. Run it on the host (or inside the container)
|
||||
with `DATABASE_URL` pointing at your database:
|
||||
|
||||
```bash
|
||||
# Interactive (prompts for the new password):
|
||||
DATABASE_URL=sqlite://./data/solitaire.db \
|
||||
./solitaire_server --reset-password <username>
|
||||
|
||||
# Non-interactive (piped from a script or password manager):
|
||||
echo "new_password" | \
|
||||
DATABASE_URL=sqlite://./data/solitaire.db \
|
||||
./solitaire_server --reset-password <username>
|
||||
|
||||
# Inside a running Docker container:
|
||||
docker compose exec server sh -c \
|
||||
'echo "new_password" | ./solitaire_server --reset-password alice'
|
||||
```
|
||||
|
||||
On success the user's `password_hash` is updated and **all active refresh
|
||||
tokens are deleted**, so every open session must log in again with the new
|
||||
password. `JWT_SECRET` does not need to be set for this command.
|
||||
|
||||
Reference in New Issue
Block a user