dart_otp 1.3.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 64

dart_otp #

pub package Build Status Coverage Status

dart_otp is a dart package to generate and verify one-time passwords that were used to implement 2FA and MFA authentication method in web applications and other login-required systems.

The package was implement based on RFC4226 (HOTP: An HMAC-Based One-Time Password Algorithm) and RFC6238 (TOTP: Time-Based One-Time Password Algorithm).

Feature #

  • Create and verify a HOTP object
  • Create and verify a TOTP object
  • Generate a otpauth url with the b32 encoded string
  • Support for OTP tokens encrypted with SHA1, SHA256, SHA384 and SHA512

Installation #

Pubspec #

Add dart_otp as a dependency in your pubspec.yaml file.

dependencies:
  dart_otp: ^1.3.0

Example #

Time-based OTPs #

import 'package:dart_otp/dart_otp.dart';

void main() {

  /// default initialization for intervals of 30 seconds and 6 digit tokens
  TOTP totp = TOTP(secret: "J22U6B3WIWRRBTAV");

  /// initialization for custom interval and digit values
  TOTP totp = TOTP(secret: "J22U6B3WIWRRBTAV", interval: 60, digits: 8);

  totp.now(); /// => 432143

  /// verify for the current time
  totp.verify(otp: 432143); /// => true

  /// verify after 30s
  totp.verify(otp: 432143); /// => false
}

Counter-based OTPs #

import 'package:dart_otp/dart_otp.dart';

void main() {

  /// default initialization 6 digit tokens
  HOTP hotp = HOTP(secret: "J22U6B3WIWRRBTAV");

  /// initialization for custom digit value
  HOTP hotp = HOTP(secret: "J22U6B3WIWRRBTAV", counter: 50, digits: 8);

  hotp.at(counter: 0); /// => 432143
  hotp.at(counter: 1); /// => 231434
  hotp.at(counter: 2132); /// => 242432

  /// verify with a counter
  hotp.verify(otp: 242432, counter: 2132); /// => true
  hotp.verify(otp: 242432, counter: 2133); /// => false
}

Release notes #

See CHANGELOG.md.

[1.0.1]

  • Release the first stable version

[1.0.2]

  • Add docs
  • Add example file
  • Fix dart format warning

[1.0.3]

  • Add documentation
  • Minor code style enhancements
  • Make interval and digits properties public for time based tokens

[1.1.0]

  • Add unit tests
  • Update documentation
  • Update components API
  • Refactor some components
  • Minor code style enhancements
  • Increase options export option for generate url function

[1.2.0]

  • Minor enhancements
  • Add new counter property inside hotp object
  • Update documentation according to dart guidelines
  • Add support for SHA256 algorithm (available: SHA1 and SHA256)
  • Add extra url proprties to otp object in order to export:
    • Digits
    • Issuer
    • Period
    • Account
    • Counter
    • Algorithm

[1.3.0]

  • Minor enhancements
  • Add support for SHA384 and SHA512 algorithm (available: SHA1, SHA256, SHA384 and SHA512)

example/example.dart

import 'package:dart_otp/dart_otp.dart';

void main() {
  TOTP totp = TOTP(secret: "J22U6B3WIWRRBTAV");
  HOTP hotp = HOTP(secret: "J22U6B3WIWRRBTAV");

  print(totp.now());
  print(totp.value(date: DateTime.parse('2019-01-01 00:00:00.000')));

  print(hotp.at(counter: 0));
  print(hotp.at(counter: 2019));
}

Use this package as a library

1. Depend on it

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


dependencies:
  dart_otp: ^1.3.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:dart_otp/dart_otp.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
27
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
64
Learn more about scoring.

We analyzed this package on Oct 16, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:dart_otp/dart_otp.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.13.0 <3.0.0
base32 ^1.0.1 1.0.1
crypto ^2.0.6 2.1.3
Transitive dependencies
charcode 1.1.2
collection 1.14.12
convert 2.1.1
typed_data 1.1.6
Dev dependencies
test ^1.6.5
test_coverage ^0.2.0