From 23894e0978e4708fc7b5c3c0371628c70f45580b Mon Sep 17 00:00:00 2001 From: arieeefajar Date: Wed, 14 May 2025 14:12:50 +0700 Subject: [PATCH] fix(auth): fix function validate confirm password --- .phpunit.result.cache | 1 + .../Auth/PasswordResetLinkController.php | 6 +++- tests/Unit/CertaintyFactorTest.php | 30 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 .phpunit.result.cache create mode 100644 tests/Unit/CertaintyFactorTest.php diff --git a/.phpunit.result.cache b/.phpunit.result.cache new file mode 100644 index 0000000..4f2b853 --- /dev/null +++ b/.phpunit.result.cache @@ -0,0 +1 @@ +{"version":1,"defects":{"Tests\\Unit\\CertaintyFactorTest::test_cf_combination_opposite_signs":7,"Tests\\Feature\\Auth\\AuthenticationTest::test_login_screen_can_be_rendered":8,"Tests\\Feature\\Auth\\AuthenticationTest::test_users_can_authenticate_using_the_login_screen":8,"Tests\\Feature\\Auth\\AuthenticationTest::test_users_can_not_authenticate_with_invalid_password":8,"Tests\\Feature\\Auth\\AuthenticationTest::test_users_can_logout":8,"Tests\\Feature\\Auth\\EmailVerificationTest::test_email_verification_screen_can_be_rendered":8,"Tests\\Feature\\Auth\\EmailVerificationTest::test_email_can_be_verified":8,"Tests\\Feature\\Auth\\EmailVerificationTest::test_email_is_not_verified_with_invalid_hash":8,"Tests\\Feature\\Auth\\PasswordConfirmationTest::test_confirm_password_screen_can_be_rendered":8,"Tests\\Feature\\Auth\\PasswordConfirmationTest::test_password_can_be_confirmed":8,"Tests\\Feature\\Auth\\PasswordConfirmationTest::test_password_is_not_confirmed_with_invalid_password":8,"Tests\\Feature\\Auth\\PasswordResetTest::test_reset_password_link_screen_can_be_rendered":8,"Tests\\Feature\\Auth\\PasswordResetTest::test_reset_password_link_can_be_requested":8,"Tests\\Feature\\Auth\\PasswordResetTest::test_reset_password_screen_can_be_rendered":8,"Tests\\Feature\\Auth\\PasswordResetTest::test_password_can_be_reset_with_valid_token":8,"Tests\\Feature\\Auth\\PasswordUpdateTest::test_password_can_be_updated":8,"Tests\\Feature\\Auth\\PasswordUpdateTest::test_correct_password_must_be_provided_to_update_password":8,"Tests\\Feature\\Auth\\RegistrationTest::test_registration_screen_can_be_rendered":8,"Tests\\Feature\\Auth\\RegistrationTest::test_new_users_can_register":8,"Tests\\Feature\\ProfileTest::test_profile_page_is_displayed":8,"Tests\\Feature\\ProfileTest::test_profile_information_can_be_updated":8,"Tests\\Feature\\ProfileTest::test_email_verification_status_is_unchanged_when_the_email_address_is_unchanged":8,"Tests\\Feature\\ProfileTest::test_user_can_delete_their_account":8,"Tests\\Feature\\ProfileTest::test_correct_password_must_be_provided_to_delete_account":8,"Tests\\Unit\\StoreEvaluationTest::test_store_saves_evaluation_successfully":8},"times":{"Tests\\Unit\\CertaintyFactorTest::test_cf_positive_combination":0.009,"Tests\\Unit\\CertaintyFactorTest::test_cf_negative_combination":0,"Tests\\Unit\\CertaintyFactorTest::test_cf_combination_opposite_signs":0.001,"Tests\\Unit\\ExampleTest::test_that_true_is_true":0.031,"Tests\\Feature\\ExampleTest::test_the_application_returns_a_successful_response":5.614,"Tests\\Unit\\StoreEvaluationTest::test_store_saves_evaluation_successfully":1.869}} \ No newline at end of file diff --git a/app/Http/Controllers/Auth/PasswordResetLinkController.php b/app/Http/Controllers/Auth/PasswordResetLinkController.php index 75aa024..9cd3e0b 100644 --- a/app/Http/Controllers/Auth/PasswordResetLinkController.php +++ b/app/Http/Controllers/Auth/PasswordResetLinkController.php @@ -69,12 +69,16 @@ public function createNewPasswordForm(Request $request) public function storeNewPasswordForm(Request $request) { $data = DB::table('password_reset_tokens')->where('email', $request->email)->first(); - if ($data == null || !Hash::check($request->token, $data->token)) { toast('Link reset password tidak valid atau kedaluwarsa', 'error')->position('top')->autoclose(3000); return redirect()->back(); } + if ($request->new_password != $request->confirm_password) { + toast('Konfirmasi Password tidak cocok', 'error')->position('top')->autoclose(3000); + return redirect()->back(); + } + DB::beginTransaction(); $user = User::where('email', $request->email)->first(); $user->password = Hash::make($request->new_password); diff --git a/tests/Unit/CertaintyFactorTest.php b/tests/Unit/CertaintyFactorTest.php new file mode 100644 index 0000000..412dc82 --- /dev/null +++ b/tests/Unit/CertaintyFactorTest.php @@ -0,0 +1,30 @@ +calculateCFc(0.6, 0.4); + $this->assertEquals(0.76, $result); + } + + public function test_cf_negative_combination() + { + $controller = new AssesmentFormController(); + $result = $controller->calculateCFc(-0.6, -0.4); + $this->assertEquals(-0.76, $result); + } + + public function test_cf_combination_opposite_signs() + { + $controller = new AssesmentFormController(); + $result = $controller->calculateCFc(0.6, -0.4); + $this->assertEqualsWithDelta(0.333, $result, 0.001); + } +}