return;
}
- $stored = $this->credentialsManager->retrieve($event->getUser()->getUID(), LoginCredentials::CREDENTIALS_IDENTIFIER);
- $update = isset($stored['password']) && $stored['password'] !== $event->getPassword();
- if (!$update && $event instanceof UserLoggedInEvent) {
- $update = isset($stored['user']) && $stored['user'] !== $event->getLoginName();
+ $storedCredentials = $this->credentialsManager->retrieve($event->getUser()->getUID(), LoginCredentials::CREDENTIALS_IDENTIFIER);
+
+ if (!$storedCredentials) {
+ return;
+ }
+
+ $newCredentials = $storedCredentials;
+ $shouldUpdate = false;
+
+ if (isset($storedCredentials['password']) && $storedCredentials['password'] !== $event->getPassword()) {
+ $shouldUpdate = true;
+ $newCredentials['password'] = $event->getPassword();
}
- if ($stored && $update) {
- $credentials = [
- 'user' => $event->getLoginName(),
- 'password' => $event->getPassword()
- ];
+ if (isset($storedCredentials['user']) && $event instanceof UserLoggedInEvent && $storedCredentials['user'] !== $event->getLoginName()) {
+ $shouldUpdate = true;
+ $newCredentials['user'] = $event->getLoginName();
+ }
- $this->credentialsManager->store($event->getUser()->getUID(), LoginCredentials::CREDENTIALS_IDENTIFIER, $credentials);
+ if ($shouldUpdate) {
+ $this->credentialsManager->store($event->getUser()->getUID(), LoginCredentials::CREDENTIALS_IDENTIFIER, $newCredentials);
}
}
}