private function updatePasswordHash($login, $password, SPIUser $spiUser)
    {
        if ($spiUser->hashAlgorithm === $this->settings['hashType']) {
            return;
        }

        $spiUser->passwordHash = $this->createPasswordHash($login, $password, null, $this->settings['hashType']);
        $spiUser->hashAlgorithm = $this->settings['hashType'];

        $this->repository->beginTransaction();
        $this->userHandler->update($spiUser);
        $reloadedSpiUser = $this->userHandler->load($spiUser->id);

        if ($reloadedSpiUser->passwordHash === $spiUser->passwordHash) {
            $this->repository->commit();
        } else {
            // Password hash was not correctly saved, possible cause: EZP-28692
            $this->repository->rollback();
            if (isset($this->logger)) {
                $this->logger->critical('Password hash could not be updated. Please verify that your database schema is up to date.');
            }

            throw new BadStateException(
                'user',
                'Could not save updated password hash, reverting to previous hash. Please verify that your database schema is up to date.'
            );
        }
    }