otp
3.2.1, released 8 weeks ago by yuli.dev
Generate TOTP/HOTP codes per RFC6238/4226 with Base32 secrets and optional Google Auth mode.
WASM-readyRock solid
What it does
This library provides functions to generate time‑based and counter‑based one‑time passwords. It supports SHA‑256/512 algorithms, Google Authenticator compatibility, and exposes utilities like remainingSeconds and constant‑time verification.
AI-written summary of version 3.2.1, based on the package's README and metadata. Report an inaccuracy
Use it when
- Implementing 2FA or OTP verification in a Flutter app
- Generating codes for Google Authenticator or similar apps
- Testing OTP logic in unit tests
Skip it when
- You need a full authentication flow with user management
- Your secrets are not Base32 and you prefer not to convert them
Strengths
- RFC‑compliant implementation
- Supports SHA‑256/512 and Google Auth mode
- Provides remainingSeconds helper
- Simple API, no UI dependencies
Weaknesses
- Only accepts Base32 secrets
- constantTimeVerification may not be fully reliable
- No built‑in UI components
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 3
Add `otp: 3.2.1` to pubspec and import `package:otp/otp.dart`
import 'package:otp/otp.dart';
final code = OTP.generateTOTPCodeString('JBSWY3DPEHPK3PXP', DateTime.now().millisecondsSinceEpoch);
print(code);Alternatives
Packages that do the same job and could replace otp.
Works with
Packages commonly used together with otp: ones it builds on, ones built on it, and its own family.