Skip to content

Commit 4062d82

Browse files
committed
fix(lostpassword): Delete lost password token on password change
Signed-off-by: Carl Schwan <carl.schwan@nextcloud.com>
1 parent 362a857 commit 4062d82

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

core/Application.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use OC\Authentication\Listeners\UserDeletedWebAuthnCleanupListener;
1919
use OC\Authentication\Notifications\Notifier as AuthenticationNotifier;
2020
use OC\Core\Listener\BeforeTemplateRenderedListener;
21+
use OC\Core\Listener\PasswordUpdatedListener;
2122
use OC\Core\Notification\CoreNotifier;
2223
use OC\TagManager;
2324
use OCP\AppFramework\App;
@@ -28,6 +29,7 @@
2829
use OCP\EventDispatcher\IEventDispatcher;
2930
use OCP\Notification\IManager as INotificationManager;
3031
use OCP\User\Events\BeforeUserDeletedEvent;
32+
use OCP\User\Events\PasswordUpdatedEvent;
3133
use OCP\User\Events\UserDeletedEvent;
3234
use OCP\Util;
3335

@@ -305,6 +307,7 @@ public function __construct() {
305307
$eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, UserDeletedFilesCleanupListener::class);
306308
$eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedFilesCleanupListener::class);
307309
$eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedWebAuthnCleanupListener::class);
310+
$context->registerEventListener(PasswordUpdatedEvent::class, PasswordUpdatedListener::class);
308311

309312
// Tags
310313
$eventDispatcher->addServiceListener(UserDeletedEvent::class, TagManager::class);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OC\Core\Listener;
11+
12+
use OCP\EventDispatcher\Event;
13+
use OCP\EventDispatcher\IEventListener;
14+
use OCP\Security\VerificationToken\IVerificationToken;
15+
use OCP\User\Events\PasswordUpdatedEvent;
16+
17+
/**
18+
* @template-implements IEventListener<PasswordUpdatedEvent>
19+
*/
20+
class PasswordUpdatedListener implements IEventListener {
21+
public function __construct(
22+
readonly private IVerificationToken $verificationToken,
23+
) {
24+
25+
}
26+
27+
public function handle(Event $event): void {
28+
if ($event instanceof PasswordUpdatedEvent) {
29+
$this->verificationToken->delete('', $event->getUser(), 'lostpassword');
30+
}
31+
}
32+
}

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,7 @@
13881388
'OC\\Core\\Exception\\ResetPasswordException' => $baseDir . '/core/Exception/ResetPasswordException.php',
13891389
'OC\\Core\\Listener\\BeforeMessageLoggedEventListener' => $baseDir . '/core/Listener/BeforeMessageLoggedEventListener.php',
13901390
'OC\\Core\\Listener\\BeforeTemplateRenderedListener' => $baseDir . '/core/Listener/BeforeTemplateRenderedListener.php',
1391+
'OC\\Core\\Listener\\PasswordUpdatedListener' => $baseDir . '/core/Listener/PasswordUpdatedListener.php',
13911392
'OC\\Core\\Middleware\\TwoFactorMiddleware' => $baseDir . '/core/Middleware/TwoFactorMiddleware.php',
13921393
'OC\\Core\\Migrations\\Version13000Date20170705121758' => $baseDir . '/core/Migrations/Version13000Date20170705121758.php',
13931394
'OC\\Core\\Migrations\\Version13000Date20170718121200' => $baseDir . '/core/Migrations/Version13000Date20170718121200.php',

lib/composer/composer/autoload_static.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
1111
);
1212

1313
public static $prefixLengthsPsr4 = array (
14-
'O' =>
14+
'O' =>
1515
array (
1616
'OC\\Core\\' => 8,
1717
'OC\\' => 3,
@@ -28,15 +28,15 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
2828
);
2929

3030
public static $prefixDirsPsr4 = array (
31-
'OC\\Core\\' =>
31+
'OC\\Core\\' =>
3232
array (
3333
0 => __DIR__ . '/../../..' . '/core',
3434
),
35-
'OC\\' =>
35+
'OC\\' =>
3636
array (
3737
0 => __DIR__ . '/../../..' . '/lib/private',
3838
),
39-
'OCP\\' =>
39+
'OCP\\' =>
4040
array (
4141
0 => __DIR__ . '/../../..' . '/lib/public',
4242
),
@@ -1437,6 +1437,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
14371437
'OC\\Core\\Exception\\ResetPasswordException' => __DIR__ . '/../../..' . '/core/Exception/ResetPasswordException.php',
14381438
'OC\\Core\\Listener\\BeforeMessageLoggedEventListener' => __DIR__ . '/../../..' . '/core/Listener/BeforeMessageLoggedEventListener.php',
14391439
'OC\\Core\\Listener\\BeforeTemplateRenderedListener' => __DIR__ . '/../../..' . '/core/Listener/BeforeTemplateRenderedListener.php',
1440+
'OC\\Core\\Listener\\PasswordUpdatedListener' => __DIR__ . '/../../..' . '/core/Listener/PasswordUpdatedListener.php',
14401441
'OC\\Core\\Middleware\\TwoFactorMiddleware' => __DIR__ . '/../../..' . '/core/Middleware/TwoFactorMiddleware.php',
14411442
'OC\\Core\\Migrations\\Version13000Date20170705121758' => __DIR__ . '/../../..' . '/core/Migrations/Version13000Date20170705121758.php',
14421443
'OC\\Core\\Migrations\\Version13000Date20170718121200' => __DIR__ . '/../../..' . '/core/Migrations/Version13000Date20170718121200.php',

0 commit comments

Comments
 (0)