From 4d420122cc313507618fed54c181dd0ceeb6384d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amel=20Junuzovi=C4=87?= Date: Mon, 23 Nov 2026 14:13:23 +0100 Subject: [PATCH] fix: handle password reset checks without a password identity --- docs/user_management/forcing_password_reset.md | 5 ++++- src/Traits/Resettable.php | 6 +++--- tests/Authentication/ForcePasswordResetTest.php | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/docs/user_management/forcing_password_reset.md b/docs/user_management/forcing_password_reset.md index 97237053c..d8b606cca 100644 --- a/docs/user_management/forcing_password_reset.md +++ b/docs/user_management/forcing_password_reset.md @@ -28,7 +28,10 @@ the following methods to do so. ### Check if a User Requires Password Reset -When you need to check if a user requires password reset, you can do so using the `requiresPasswordReset()` method on the `User` entity. Returns boolean `true`/`false`. +Call `requiresPasswordReset()` on the `User` entity to check whether its +email/password identity requires a password reset. The method returns `false` +for users without an email/password identity. These users can continue through +the `force-reset` filter. ```php if ($user->requiresPasswordReset()) { diff --git a/src/Traits/Resettable.php b/src/Traits/Resettable.php index c68c0ba1b..4be8ebbcc 100644 --- a/src/Traits/Resettable.php +++ b/src/Traits/Resettable.php @@ -23,15 +23,15 @@ trait Resettable { /** - * Returns true|false based on the value of the - * force reset column of the user's identity. + * Checks whether the user's email/password identity requires a password reset. + * A user without that identity does not require a Shield password reset. */ public function requiresPasswordReset(): bool { $identityModel = model(UserIdentityModel::class); $identity = $identityModel->getIdentityByType($this, Session::ID_TYPE_EMAIL_PASSWORD); - return $identity->force_reset; + return $identity->force_reset ?? false; } /** diff --git a/tests/Authentication/ForcePasswordResetTest.php b/tests/Authentication/ForcePasswordResetTest.php index 09ae154c0..73c9ac822 100644 --- a/tests/Authentication/ForcePasswordResetTest.php +++ b/tests/Authentication/ForcePasswordResetTest.php @@ -62,6 +62,23 @@ public function testUserRequiresPasswordReset(): void $this->assertTrue($user->requiresPasswordReset()); } + public function testUserWithoutEmailPasswordIdentityDoesNotRequirePasswordReset(): void + { + $user = fake(UserModel::class); + + $this->assertFalse($user->requiresPasswordReset()); + } + + public function testForceResetFilterAllowsUserWithoutEmailPasswordIdentity(): void + { + $user = fake(UserModel::class); + + $result = $this->actingAs($user)->get('profile'); + + $result->assertStatus(200); + $result->assertSee('Profile'); + } + public function testForcePasswordResetOnUser(): void { $user = fake(UserModel::class);