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

插件详情v0.3.2

flutter_otp

一个用于发送和验证OTP的Flutter包。四位数字OTP(可自定义)作为短信发送到给定的电话号码(及国家代码)。

近 30 天下载
111
喜欢数
85
Pub 分数
40

安装插件

flutter pub add flutter_otp

插件介绍

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

一个用于通过短信简化发送和验证一次性密码(OTP)流程的Flutter包。它支持可自定义的OTP长度,通常为四位数字,并与包含国家代码的电话号码集成。该包通过安全高效地处理OTP生成、传递和验证,简化了用户认证流程。适用于需要双因素认证的登录、注册或账户恢复工作流。

适合场景

  • 用户登录使用OTP
  • 账户验证
  • 密码重置
  • 双因素认证
  • 安全接入
  • 基于短信的认证

主要特点

  • 可自定义的OTP长度
  • 短信集成用于OTP发送
  • 支持国家代码
  • OTP 验证的简单 API
  • 安全的OTP处理
  • 轻松设置,配置最少

适合对象

  • 需要OTP验证的移动应用
  • 认证系统
  • 用户注册流程
  • 注重安全的应用程序
  • 使用短信双因素认证的应用程序
  • 寻求快速OTP实现的开发者

使用建议

  • 依赖外部短信服务
  • 仅限短信发送方式
  • 无内置的一次性密码过期管理
  • 需要对失败的投递进行适当的错误处理
  • 依赖第三方短信服务提供商的可靠性
  • 不适用于离线使用

原始 README

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

Awesome Flutter contributions welcome Known Vulnerabilities Build Status

flutter_otp

A Flutter package for Android and iOS for sending and verifying OTP to a Phone number.

Important message for existing Users
NEW FEATURE !!

Now you can send the message to any country code passed as a parameter to the interface (sendOtp() function)

Installing

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

dependencies:
  flutter_otp: ^0.3.2
2. Install it

You can install packages from the command line: with Flutter:

$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:flutter_otp/flutter_otp.dart';

Functions

The important functions used in the package are :

  1. sendOtp() to send a OTP (four digit by default, but customizable):
void sendOtp(String phoneNumber, [String messageText]) {
    ...        
}

NOTE:

  1. 10 digit phoneNumber should be passed.
  2. parameter "messageText" is optional. By default the message text is "Your OTP is : XXXX". If "messageText" parameter is passed then message is sent as " XXXX".
  1. resultChecker() which takes the OTP entered by the user as a parameter. The function returns true if OTP is matched, else false is returned.
bool resultChecker(int enteredOtp) {
    ...
} 

NOTE: The OTP entered by user (say, through TextField widget or TextFormField widget etc) is to be passed as a parameter to this function.

Usage

To use this package in your application you need to have a sim card in your mobile.

Example Usage:

...
sendOtp('958347XXXX');  //Pass phone number as String

...

int enteredOtp;
TextField(
  onChanged: (val) {
    enteredOtp = val;    
  }
)

...

bool isCorrectOTP = resultChecker();
if(isCorrectOTP) {
    print('Success');
} else {
    print('Failure');
}
...

OR custom "messageText" can be passed as parameter to sendOTP

...
sendOtp('958347XXXX', 'OTP is : ');  //Pass phone number and Custom messaseText as String

...

int enteredOtp;
TextField(
  onChanged: (val) {
    enteredOtp = val;    
  }
)

...

bool isCorrectOTP = resultChecker();
if(isCorrectOTP) {
    print('Success');
} else {
    print('Failure');
}
...

Contributors

  1. Fawaz Hussain
  2. Jerin Francis

:star: the repo to show support!

More Information

Pub package Flutter documentation.

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目

暂无相关数据。