搜索插件、代码仓与 APP 分类

插件详情v3.8.1

cloudflare_turnstile

一种免费的验证码替代方案,用于增强安全性和防范机器人。

AndroidiOSWebmacOSWindows
近 30 天下载
6万
喜欢数
50
Pub 分数
160

安装插件

flutter pub add cloudflare_turnstile

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter 包,用于集成 Cloudflare Turnstile,这是一种免费的 CAPTCHA 替代方案,旨在保护应用程序免受机器人攻击,同时提供无缝的用户体验。它用简单的、注重隐私的验证挑战取代了传统的 CAPTCHA,无需复杂的交互即可验证人类用户。该包支持 Android、iOS、Web、macOS 和 Windows 等多个平台,非常适合需要强大机器人防护功能的跨平台应用。Turnstile 使用先进的风险分析来最大限度地减少合法用户的使用摩擦。实现简单,配置极少,适用于表单、登录界面以及任何容易受到滥用的高流量入口点。

适合场景

  • 保护登录表单
  • 保护表单提交
  • 防止机器人驱动的注册
  • 增强API端点安全性
  • 减少评论区的垃圾信息

主要特点

  • 免费使用
  • 低用户摩擦
  • 注重隐私的设计
  • 跨平台支持
  • 实时风险分析

适合对象

  • Web 和移动应用
  • 高流量网站
  • 用户注册系统
  • API端点
  • 面向全球受众的应用程序

使用建议

  • 需要互联网连接
  • 依赖于 Cloudflare 的基础设施
  • 有限的自定义选项
  • 可能需要后端验证
  • 不适用于离线环境

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Flutter Cloudflare Turnstile Pub

head

Cloudflare turnstile is a free CAPTCHAs Alternative, Turnstile delivers frustration-free, CAPTCHA-free web experiences to website visitors - with just a simple snippet of free code. Moreover, Turnstile stops abuse and confirms visitors are real without the data privacy concerns or awful user experience of CAPTCHAs.

[!WARNING]

This package is unofficial and not endorsed by Cloudflare. Use it at your own discretion.

Installation

flutter pub add cloudflare_turnstile

For Windows platform, please follow the inappwebview windows setup instructions.

Example

Here's a quick example that shows how to add Cloudflare Turnstile widget to your flutter app

import 'package:flutter/material.dart';
import 'package:cloudflare_turnstile/cloudflare_turnstile.dart';

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    // Turnstile widget configuration
    final TurnstileOptions options = const TurnstileOptions(
      size: TurnstileSize.normal,
      theme: TurnstileTheme.light,
      language: 'ar',
      retryAutomatically: false,
      refreshTimeout: TurnstileRefreshTimeout.manual,
    );

    return Scaffold(
      body: Center(
        child: CloudflareTurnstile(
          siteKey: '3x00000000000000000000FF', //Change with your site key
          baseUrl: 'http://localhost/',
          onTokenReceived: (token) {
            print(token);
          },
        ),
      ),
    );
  }
}

For Android and iOS platforms you need to provide the baseUrl parameter with the actual URL of your Turnstile Widget Domains list. baseUrl must be the same as the list of domains when creating a Widget.

Using Turnstile invisible mode

Here's how to use Cloudflare's invisible Turnstile, which automatically solves the challenge in the background

import 'package:cloudflare_turnstile/cloudflare_turnstile.dart';


class TurnstileService {
  /// Retrieves the CloudFlare Turnstile token using invisible mode.
  static Future<String?> get token async {
    // Initialize an instance of invisible Cloudflare Turnstile with your site key
    final turnstile = CloudflareTurnstile.invisible(
      siteKey: '1x00000000000000000000BB', // Replace with your actual site key
    );

    try {
      // Get the Turnstile token
      final token = await turnstile.getToken();
      return token; // Return the token upon success
    } on TurnstileException catch (e) {
      // Handle Turnstile failure
      print('Challenge failed: ${e.message}');
    } finally {
      // Ensure the Turnstile instance is properly disposed of
      turnstile.dispose();
    }

    // Return null if the token couldn't be generated
    return null;
  }
}

[!WARNING]

It's important to call dispose() on the CloudflareTurnstile instance when you no longer need it. This ensures that resources are properly cleaned up, preventing any potential memory issues.

Contribution

Your contributions are welcome and greatly valued! If you have ideas, suggestions, or improvements, feel free to open an issue or submit a pull request. Every bit of help is appreciated, and your input can make a big difference. Just ensure your contributions fit with the project's goals and guidelines.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

所属分类

依赖

依赖清单 2 项

源码仓库

使用此插件的项目

所在榜单