Skip to content

Commit 4007c5c

Browse files
authored
Merge pull request #405 from 2pisoftware/develop
release: merge develop into main
2 parents 721f1c4 + c86cf71 commit 4007c5c

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

system/modules/auth/actions/forgotpassword.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use Carbon\CarbonInterval;
4+
35
function forgotpassword_GET(Web $w)
46
{
57
// Check if logged in already
@@ -36,11 +38,15 @@ function forgotpassword_POST(Web $w)
3638
$user->dt_password_reset_at = time();
3739
$user->update();
3840

41+
// default 30 minutes
42+
$expiry = Config::get("auth.login.password.reset_token_expiry", 30 * 60);
43+
$readable_expiry = CarbonInterval::seconds($expiry)->cascade()->forHumans();
44+
3945
// Send email
4046
$message = "Hello {$user->getFullName()},\n<br/>";
4147
$message .= "Please go to this link to reset your password:<br/>\n";
42-
$message .= "<a href=\"https://" . $_SERVER["HTTP_HOST"] . "/auth/resetpassword?email={$user_contact->email}&token={$user->password_reset_token}\">https://"
43-
. $_SERVER["HTTP_HOST"] . "/auth/resetpassword?token={$user->password_reset_token}</a>\n<br/>You have 24 hours to reset your password.<br/><br/>";
48+
$message .= "<a href=\"https://" . $_SERVER["HTTP_HOST"] . "/auth/resetpassword?token={$user->password_reset_token}\">https://"
49+
. $_SERVER["HTTP_HOST"] . "/auth/resetpassword?token={$user->password_reset_token}</a>\n<br/>You have {$readable_expiry} to reset your password.<br/><br/>";
4450
$message .= "Thank you,\n<br/>". Config::get('main.company_name', 'Cosine');
4551

4652
$result = MailService::getInstance($w)->sendMail($user_contact->email, $support_email, Config::get("main.application_name") . " password reset", $message);

system/modules/auth/actions/resetpassword.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use Carbon\CarbonInterval;
34
use Html\Form\InputField\Password;
45

56
function resetpassword_GET(Web $w)
@@ -13,8 +14,13 @@ function resetpassword_GET(Web $w)
1314
if (!empty($user->id)) {
1415
// Check that the password reset hasn't expired
1516
LogService::getInstance($w)->setLogger("AUTH")->debug("USER: " . $user->id . " TIME: " . time() . " USER_RESET: " . $user->dt_password_reset_at . " RESULT: " . (time() - $user->dt_password_reset_at));
16-
if ((time() - $user->dt_password_reset_at) > 86400) {
17-
$w->msg("Your token has expired (max 24 hours), please submit for a new one", "/auth/forgotpassword");
17+
18+
// default 30 minutes
19+
$expiry = Config::get("auth.login.password.reset_token_expiry", 30 * 60);
20+
$readable_expiry = CarbonInterval::seconds($expiry)->cascade()->forHumans();
21+
22+
if ((time() - $user->dt_password_reset_at) > $expiry) {
23+
$w->msg("Your token has expired (max {$readable_expiry}), please submit for a new one", "/auth/forgotpassword");
1824
return;
1925
}
2026

system/modules/auth/config.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
'login' => [
1717
'password' => [
1818
'enforce_length' => false,
19-
'min_length' => 8
19+
'min_length' => 8,
20+
"reset_token_expiry" => 30 * 60 // 30 minutes
2021
],
2122
'attempts' => [
2223
'track_attempts' => false,

0 commit comments

Comments
 (0)