From 9e4e3023fa39c1c8f6016355199a439d16e8d223 Mon Sep 17 00:00:00 2001 From: Christoph Schlaepfer <1939311+Anuril@users.noreply.github.com> Date: Sun, 30 Jul 2023 15:58:11 +0200 Subject: [PATCH] Fixed Password Reset handling (#1365) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixed Passwort Reset handling so the message is the same whether the E-Mail address exists or not. * Fixed spelling & Test * Fixed Typo * Improved Staff PW Reset handling and removed both Exceptions to return true * Improved grammar & wording --------- Co-authored-by: Christoph Schläpfer Co-authored-by: Anuril Co-authored-by: Belle Aerni --- src/modules/Client/Api/Guest.php | 2 +- .../Page/html_client/mod_page_password-reset.html.twig | 2 +- src/modules/Staff/Api/Guest.php | 2 +- .../Staff/html_admin/mod_staff_password_reset.html.twig | 2 +- tests/modules/Client/Api/GuestTest.php | 6 +++--- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/modules/Client/Api/Guest.php b/src/modules/Client/Api/Guest.php index e17466120..194d4de15 100644 --- a/src/modules/Client/Api/Guest.php +++ b/src/modules/Client/Api/Guest.php @@ -160,7 +160,7 @@ class Guest extends \Api_Abstract $c = $this->di['db']->findOne('Client', 'email = ?', [$data['email']]); if (!$c instanceof \Model_Client) { - throw new \Box_Exception('Email not found in our database'); + return true; } $hash = hash('sha256', time() . random_bytes(13)); diff --git a/src/modules/Page/html_client/mod_page_password-reset.html.twig b/src/modules/Page/html_client/mod_page_password-reset.html.twig index ab0e3d926..104af9607 100644 --- a/src/modules/Page/html_client/mod_page_password-reset.html.twig +++ b/src/modules/Page/html_client/mod_page_password-reset.html.twig @@ -59,7 +59,7 @@ $(function() { 'guest/client/reset_password', $(this).serialize(), function(result) { - bb.msg("{{ 'Password reset confirmation email was sent'|trans }}"); + bb.msg("{{ 'A password reset confirmation email will be sent to you if we found an account with that email address.'|trans }}"); } ); diff --git a/src/modules/Staff/Api/Guest.php b/src/modules/Staff/Api/Guest.php index dd0b1e4b2..eadcd0829 100644 --- a/src/modules/Staff/Api/Guest.php +++ b/src/modules/Staff/Api/Guest.php @@ -145,7 +145,7 @@ class Guest extends \Api_Abstract $c = $this->di['db']->findOne('Admin', 'email = ?', [$data['email']]); if (!$c instanceof \Model_Admin) { - throw new \Box_Exception('Email not found in our database'); + return true; } $hash = hash('sha256', time() . random_bytes(13)); diff --git a/src/modules/Staff/html_admin/mod_staff_password_reset.html.twig b/src/modules/Staff/html_admin/mod_staff_password_reset.html.twig index 73b47e0da..b9bf3c135 100644 --- a/src/modules/Staff/html_admin/mod_staff_password_reset.html.twig +++ b/src/modules/Staff/html_admin/mod_staff_password_reset.html.twig @@ -15,7 +15,7 @@

{{ 'Reset your password' | trans }}

{{ 'Enter your email address. You will receive a confirmation link if your account exists.' | trans }}

-
+
diff --git a/tests/modules/Client/Api/GuestTest.php b/tests/modules/Client/Api/GuestTest.php index 5a2e34cb1..10d6359bf 100644 --- a/tests/modules/Client/Api/GuestTest.php +++ b/tests/modules/Client/Api/GuestTest.php @@ -295,9 +295,9 @@ class GuestTest extends \BBTestCase { $client = new \Box\Mod\Client\Api\Guest(); $client->setDi($di); - $this->expectException(\Box_Exception::class); - $this->expectExceptionMessage('Email not found in our database'); - $client->reset_password($data); + // expects true because we don't want to give away if the email exists or not + $result = $client->reset_password($data); + $this->assertTrue($result); } public function testconfirm_reset()