public function beforeSave(Event $event, EntityInterface $entity): bool
    {
        if (empty($this->getConfig('oldPasswordCount')) || !is_numeric($this->getConfig('oldPasswordCount'))) {
            return true;
        }

        if (!is_array($entity->last_passwords)) {
            $entity->last_passwords = [];
        }

        $lastPasswords = $entity->last_passwords;
        if (count($lastPasswords) == $this->getConfig('oldPasswordCount')) {
            array_shift($lastPasswords);
        }
        $lastPasswords[] = $entity->password;
        $entity->setAccess('last_passwords', true);
        $this->_table->patchEntity($entity, [
            'last_passwords' => $lastPasswords,
        ]);

        return true;
    }