Skip to content

Commit

Permalink
improve auth/change-password
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammadmp97 committed Sep 19, 2023
1 parent 0d685a8 commit a0723a4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/Actions/User/ChangePasswordAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function execute(User $user, $data): void
}

$user->update([
'password' => Hash::make($data['password']),
'password' => Hash::make($data['new_password']),
]);
}
}
2 changes: 1 addition & 1 deletion app/Http/Requests/ChangePasswordRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function rules(): array
{
return [
'old_password' => ['required', 'string'],
'password' => ['required', 'string', 'min:6'],
'new_password' => ['required', 'string', 'min:6', 'different:old_password'],
];
}
}
4 changes: 2 additions & 2 deletions tests/Feature/AuthControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function test_user_changes_password_using_old_password()

$this->postJson('api/auth/change-password', [
'old_password' => '12345678',
'password' => 'password',
'new_password' => 'password',
])->assertOk();

$this->assertTrue(Hash::check('password', $user->password));
Expand All @@ -74,7 +74,7 @@ public function test_user_needs_old_password_for_changing_password()

$this->postJson('api/auth/change-password', [
'old_password' => '1234',
'password' => 'password',
'new_password' => 'password',
])->assertJsonValidationErrorFor('old_password');
}
}

0 comments on commit a0723a4

Please sign in to comment.