otp 1.0.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 91

Build Status

dart-otp #

RFC6238 Time-Based One-Time Password / Google Authenticator Library

Features:

Getting Started #

Pubspec #

pub.dartlang.org: (you can use 'any' instead of a version if you just want the latest always)

dependencies:
  otp: 1.0.1
#import('package:otp/otp.dart');

Start generating tokenss.

// Generate TOTP code.
OTP.generateTOTPCode("JBSWY3DPEHPK3PXP", 1362302550000); // -> 238158

// base32 decoding to original string.
OTP.generateHOTPCode("JBSWY3DPEHPK3PXP", 7); // -> 449891

API #

OTP.generateTOTPCode(String secret, int currentTime, {int length: 6, int interval: 30}) #

Generate a code for the provided secret and time.

  • secret - (String) A Base32 String.
  • currentTime - (int) The current time in milliseconds.
  • length - (int) the length of the resulting code.
  • interval - (int) refresh interval to get a new code.

Returns an int code.

OTP.generateHOTPCode(String secret, int counter, {int length: 6}) #

Generate a code for the provided secret and time.

  • secret - (String) A Base32 String.
  • counter - (int) An int counter.
  • length - (int) the length of the resulting code.

Returns an int code.

Testing #

pub run test

Release notes #

See CHANGELOG.md

v1.0.3

  • Switched to PointyCastle for crypto and support for more than SHA1 hashing for tokens (amadejkastelic)

v1.0.2

  • Add new TOTP interval parameters (optional)

v1.0.1

  • Cleanup and remove dead code

v1.0.0

  • Dart 2.0 updates

v0.1.0

  • Dart 1.0 Readiness

v0.0.4

  • Fixing crypto library.

v0.0.3

  • Fixing language changes.

v0.0.2

  • No functionality changes, just fixing a bad file state it git and in the package involving the case of the file.

v0.0.1

  • Initial Documented Release

example/example.dart

import "package:otp/otp.dart";

main() {
  var code = OTP.generateTOTPCode("JBSWY3DPEHPK3PXP", DateTime.now().millisecondsSinceEpoch);
  print(code);

  var code2 = OTP.generateTOTPCode("JBSWY3DPEHPK3PXP", DateTime.now().millisecondsSinceEpoch, interval: 10);
  print(code2);
}

Use this package as a library

1. Depend on it

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


dependencies:
  otp: ^1.0.3

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:otp/otp.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
82
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
91
Learn more about scoring.

We analyzed this package on Oct 21, 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:otp/otp.dart.

Health issues and suggestions

Document public APIs. (-1 points)

14 out of 14 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/otp.dart.

Run dartfmt to format lib/otp.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.13.0 <3.0.0
base32 >=1.0.1 <2.0.0 1.0.1
pointycastle ^1.0.1 1.0.1
Dev dependencies
test any