搜尋套件、儲存庫與 APP 分類

套件詳情v3.2.0

email_otp

一個快速且簡單的電子郵件身分驗證OTP發送與驗證Flutter套件。

AndroidiOSmacOSWindowsLinux
近 30 天下載
1850
喜歡數
115
Pub 分數
160

安裝套件

flutter pub add email_otp

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個輕量級的 Flutter 套件,用於發送和驗證基於電子郵件的一次性密碼(OTP),以簡化使用者驗證流程。它支援快速整合電子郵件 OTP 流程,設定簡單,適用於 Android、iOS、macOS、Windows 與 Linux 等多個平台。此套件處理 OTP 產生與驗證的後端通訊,減少開發安全登入系統所需時間。非常適合需要安全無密碼登入或帳戶驗證的應用程式。

適用情境

  • 無密碼登入
  • 帳戶驗證
  • 安全的使用者驗證
  • 雙因素驗證
  • 重設遺忘的密碼

主要特色

  • 簡單的OTP產生
  • 基於電子郵件的驗證
  • 跨平台支援
  • 最小化樣板程式碼
  • 與 Firebase 或自定義後端輕鬆整合

適合對象

  • 開發安全認證的開發者
  • 需要快速OTP工作流程的應用程式
  • 使用電子郵件作為主要身分的項目
  • 初創企業優先考慮快速功能部署
  • 避免複雜認證基礎設施的團隊

使用建議

  • 需要一個後端服務來處理OTP
  • 依賴可靠的電子郵件投遞
  • 不適合高數量交易郵件
  • 生產環境中可能需要速率限制
  • 使用者體驗取決於電子郵件提供者的可靠性

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Email OTP is a Flutter package designed to simplify email authentication using one-time passwords (OTPs). With Email OTP, you can effortlessly generate OTPs and send them to users' email addresses, ensuring secure identity verification. This package offers an efficient and secure method for incorporating email-based OTP authentication into your Flutter applications.

Email OTP Banner

GitHub Sponsor

Table of Contents

Configuration

The simplest way to 🛠️ configure the EmailOTP package is by calling the config method.

void main() {
  EmailOTP.config(
    appName: 'MyApp',
    otpType: OTPType.numeric,
    emailTheme: EmailTheme.v1,
  );
}

SMTP Configuration (Required)

⚠️ IMPORTANT: As of version 3.1.0, this package no longer uses a default server. You MUST configure your own SMTP server to send emails.

  EmailOTP.setSMTP(
    host: 'smtp.gmail.com',
    emailPort: EmailPort.port587,
    secureType: SecureType.tls,
    username: 'your-email@gmail.com',
    password: 'your-app-password',
  );

Note: For Gmail, use an App Password if 2-Step Verification is enabled.

Advanced Configuration

For more control over the OTP generation and email settings, you can pass various parameters to the config method.

void main() {
  EmailOTP.config(
    appName: 'App Name',
    otpType: OTPType.numeric,
    expiry : 30000,
    emailTheme: EmailTheme.v6,
    appEmail: 'me@rohitchouhan.com',
    otpLength: 6,
    headers: {
      'Reply-To': 'support@rohitchouhan.com'
    }
  );
}

Parameters

  1. host: The hostname of your SMTP server.
  2. emailPort: The port number used by the SMTP server. Supported values include:
    • EmailPort.port25
    • EmailPort.port465
    • EmailPort.port587
    • EmailPort.port1025 (For MailHog/Local Testing)
  3. secureType: The type of security used by the SMTP server. Supported values include:
    • SecureType.none
    • SecureType.tls
    • SecureType.ssl
  4. username: The username for your SMTP server account.
  5. password: The password for your SMTP server account.

By configuring these parameters, you can ensure that your application is able to send OTP emails securely and efficiently.

Themes

Theme Theme Preview
EmailTheme.v1
EmailTheme.v2
EmailTheme.v3
EmailTheme.v4
EmailTheme.v5
EmailTheme.v6
EmailTheme.v7
EmailTheme.v8
EmailTheme.v9
EmailTheme.v10

Template (Optional)

You can also customize the email 🌐 template used to send the OTP. Use the setTemplate method to provide your own HTML template.

void main() {
  EmailOTP.config();
  EmailOTP.setTemplate(
    template: '''
    <div style="background-color: #f4f4f4; padding: 20px; font-family: Arial, sans-serif;">
      <div style="background-color: #fff; padding: 20px; border-radius: 10px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);">
        <h1 style="color: #333;">{{appName}}</h1>
        <p style="color: #333;">Your OTP is <strong>{{otp}}</strong></p>
        <p style="color: #333;">This OTP is valid for 5 minutes.</p>
        <p style="color: #333;">Thank you for using our service.</p>
      </div>
    </div>
    ''',
  );
}

Parameters

  • template: A string containing the HTML content of your custom email template. Use placeholders such as {{appName}} and {{otp}} to dynamically insert the application name and OTP respectively.

By configuring these parameters and using a custom template, you can ensure that your OTP emails are tailored to match your application's branding and style.

Sending OTP

To 📧 send an 🔐 OTP to a user's email address, use the sendOTP method. This method takes the recipient's email address as a parameter.

  bool isSent = await EmailOTP.sendOTP(email: emailController.text);
  if (!isSent) {
    print(EmailOTP.lastError); // Prints specific error (e.g. SMTP Auth failed)
  }

Parameters

  • email: The recipient's email address where the OTP will be sent.

Resending OTP

If a user requests a new OTP because they didn't receive the first one, you can use resendOTP instead of generating a new one. This will re-send the existing valid OTP. If it has already expired, a new one will automatically be generated.

  EmailOTP.resendOTP(email: emailController.text);

Verifying OTP

To verify an 🔐 OTP entered by the user, use the verifyOTP method. This method takes the OTP entered by the user as a parameter and returns a boolean indicating whether the OTP is correct.

  EmailOTP.verifyOTP(otp: otpController.text)

Parameters

  • otp: The OTP entered by the user.

Get OTP

This code will print the OTP generated by the getOTP() method.

  print(EmailOTP.getOTP());

Is Expired

This method will helps you to validate your otp expiry time.

  print(EmailOTP.isExpired());

Example

👉 For a complete example, refer to the Email OTP package documentation.

Report bugs or issues

You are welcome to open a ticket on github if any 🐞 problems arise. New ideas are always welcome.

Contributors

Rahul Chouhan
Chouhan Rahul

Copyright © 2024 Rohit Chouhan. Licensed under the MIT LICENSE

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。