protected function generateToken($sMask = null, $sTable = null, $sColumn = null)
    {
        if (is_null($sMask)) {
            $sMask = $this->sTokenMask;
        }

        if (is_null($sTable)) {
            $sTable = $this->getTableName();
        }

        if (is_null($sColumn)) {
            if (!$this->tableTokenColumn) {
                throw new ModelException(static::class . '::generateToken() Token variable not set', 1);
            }
            $sColumn = $this->tableTokenColumn;
        }

        $oDb = Factory::service('Database');

        do {
            $sToken = generateToken($sMask);
            $oDb->where($sColumn, $sToken);
        } while ($oDb->count_all_results($sTable));

        return $sToken;
    }