End other sessions on password change and give admin links 72 hours

- AuthenticateSession in the web group logs out a user's other sessions
  when their password changes.
- Set-password links made by an admin use a new admin_links broker with
  its own password_setup_tokens table and a 72-hour expiry, so links
  handed over by hand don't expire in an hour. Forgot-password links
  keep 60 minutes. The reset page accepts both, and issuing or using a
  link ends the user's earlier links.
- Admin links are emailed with PasswordSetupLinkNotification; the email
  body is shared with the forgot-password email via PasswordLinkMail.
- Spec chapter 3 and CLAUDE.md describe the link lifetimes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-23 17:42:37 +02:00
co-authored by Claude Opus 5.5
parent 9af0641e17
commit 8dfc02c4e5
14 changed files with 223 additions and 35 deletions
@@ -9,6 +9,12 @@ use Livewire\Component;
new class extends Component
{
/**
* Password brokers in config/auth.php: forgot-password links, then links
* made by an admin.
*/
private const array BROKERS = ['users', 'admin_links'];
#[Locked]
public string $token = '';
@@ -43,19 +49,30 @@ new class extends Component
],
);
$status = Password::reset(
[
'email' => Str::lower(trim($this->email)),
'password' => $this->password,
'password_confirmation' => $this->password_confirmation,
'token' => $this->token,
],
function ($user, string $password): void {
$credentials = [
'email' => Str::lower(trim($this->email)),
'password' => $this->password,
'password_confirmation' => $this->password_confirmation,
'token' => $this->token,
];
// A forgot-password link (60 min) or a link made by an admin (72 h);
// each kind has its own broker. Using a link ends every other link.
foreach (self::BROKERS as $broker) {
$status = Password::broker($broker)->reset($credentials, function ($user, string $password): void {
foreach (self::BROKERS as $anyBroker) {
Password::broker($anyBroker)->deleteToken($user);
}
$user->forceFill(['password' => $password, 'remember_token' => Str::random(60)])->save();
event(new PasswordReset($user));
},
);
});
if ($status !== Password::INVALID_TOKEN) {
break;
}
}
if ($status !== Password::PASSWORD_RESET) {
$this->reset('password', 'password_confirmation');