Skip to content

Commit 8c727ae

Browse files
committed
Fix updating password
1 parent b337c64 commit 8c727ae

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

app/Http/Requests/UpdatePasswordRequest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@ class UpdatePasswordRequest extends Request
99
{
1010
public function rules()
1111
{
12-
return [
13-
'current_password' => ['sometimes', 'required', new PasscheckRule()],
12+
$rules = [
1413
'password' => ['required', 'confirmed', Password::min(8)->uncompromised()],
1514
];
15+
16+
if ($this->user()->hasPassword()) {
17+
$rules['current_password'] = ['required', new PasscheckRule()];
18+
}
19+
20+
return $rules;
1621
}
1722

1823
public function newPassword(): string

tests/Feature/SettingsTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@
8282
assertPasswordWasHashedAndSaved();
8383
});
8484

85+
test('current password is required when updating your password', function () {
86+
$this->login();
87+
88+
$this->visit('/settings')
89+
->submitForm('Update Password', [
90+
'password' => 'QFq^$cz#P@MZa5z7',
91+
'password_confirmation' => 'QFq^$cz#P@MZa5z7',
92+
])
93+
->seePageIs('/settings')
94+
->see('Something went wrong. Please review the fields below.')
95+
->see('The current password field is required.');
96+
});
97+
8598
test('users cannot update their password when it has been compromised in data leaks', function () {
8699
$this->login();
87100

0 commit comments

Comments
 (0)