{"id":16647375,"url":"https://github.com/daegalus/dart-otp","last_synced_at":"2025-04-10T01:14:09.581Z","repository":{"id":5315831,"uuid":"6498225","full_name":"daegalus/dart-otp","owner":"daegalus","description":"RFC6238 Time-Based One-Time Password / Google Authenticator Library","archived":false,"fork":false,"pushed_at":"2024-08-15T16:13:53.000Z","size":612,"stargazers_count":101,"open_issues_count":2,"forks_count":25,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-10T01:14:05.272Z","etag":null,"topics":["dart","dartlang","hacktoberfest","otp"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/daegalus.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"ko_fi":"yulian","custom":["https://paypal.me/yuliank","https://cash.app/$yulian","https://venmo.com/yuliank"]}},"created_at":"2012-11-01T22:46:28.000Z","updated_at":"2025-03-21T14:21:39.000Z","dependencies_parsed_at":"2024-06-18T21:04:35.437Z","dependency_job_id":"dff49cee-4e96-419c-a31a-e0cc0bb6f977","html_url":"https://github.com/daegalus/dart-otp","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daegalus%2Fdart-otp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daegalus%2Fdart-otp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daegalus%2Fdart-otp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daegalus%2Fdart-otp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daegalus","download_url":"https://codeload.github.com/daegalus/dart-otp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248137891,"owners_count":21053775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dart","dartlang","hacktoberfest","otp"],"created_at":"2024-10-12T08:44:36.644Z","updated_at":"2025-04-10T01:14:09.545Z","avatar_url":"https://github.com/daegalus.png","language":"Dart","funding_links":["https://ko-fi.com/yulian","https://paypal.me/yuliank","https://cash.app/$yulian","https://venmo.com/yuliank"],"categories":[],"sub_categories":[],"readme":"MAJOR BEHAVIOR CHANGE IN 3.1.0: [Explanation of Changes from 3.0 to 3.1](https://github.com/Daegalus/dart-otp/wiki/Explanation-of-Changes-from-3.0-to-3.1)\n\n![Dart](https://github.com/Daegalus/dart-otp/workflows/Dart/badge.svg)\n\n# dart-otp\n\nRFC4226/RFC6238 One-Time Password / Google Authenticator Library\n\nFeatures:\n\n- Generate TOTP (RFC6238) and HOTP (RFC4226) codes.\n- [Annotated source code](https://daegalus.github.io/dart-otp/)\n\n## Getting Started\n\n### Pubspec\n\npub.dartlang.org: (you can use 'any' instead of a version if you just want the latest always)\n\n```yaml\ndependencies:\n  otp: 3.1.2\n```\n\n```dart\nimport 'package:otp/otp.dart';\n```\n\nStart generating tokens.\n\n```dart\n// Generate TOTP code. (String versin of function incase of leading 0)\nOTP.generateTOTPCodeString(\"JBSWY3DPEHPK3PXP\", 1362302550000); // -\u003e '505548'\n\n// Generate HOTP Code.\nOTP.generateHOTPCodeString(\"JBSWY3DPEHPK3PXP\", 7); // -\u003e '006676'\n```\n\n## API\n\n### Notes\n\nThis library does not support any other secret input other than Base32. It is what is used standard most places, and by Google Authenticator.\nIf your secrets are not Base32 forms, please use my Base32 library (the one I use as a dependency for this library) or any other base32 library to encode your secret before passing it into the functions. All generate functions force decode of Base32.\n\n### Global Settings\n\n`useTOTPPaddingForHOTP` (bool, default: false) \nUses the TOTP padding method for handling secrets bigger or smaller than the mandatory sizes for SHA256/SHA512.\nThis is needed as HOTP does not have an official method of using SHA256 or SHA512 in the RFC spec and most libraries don't pad HOTP for use with SHA256 or SHA512. (examples: otplib and speakeasy from Node.js)\n\nIf you enable this, it will use the same padding as TOTP (repeating the secret to the right length) but might cause incompatibilies with other libraries. I am defaulting to no padding, as this is the predominant behavior I am finding for HOTP.\n\n### OTP.generateTOTPCode(String secret, int currentTime, {int length: 6, int interval: 30, Algorithm algorithm: Algorithm.SHA256, bool isGoogle: false})\n\nGenerate a code for the provided secret and time.\n\n- `secret` - (String) A Base32 String.\n- `currentTime` - (int) The current time in milliseconds.\n- `length` - (int) The length of the resulting code.\n- `interval` - (int) Refresh interval to get a new code.\n- `algorithm` - (Algorithm) Hashing method.\n- `isGoogle` - (bool) flag to turn off secret padding for Google Auth.\n\nReturns an `int` code. Does not preserve leading zeros.\n\n### OTP.generateTOTPCodeString(String secret, int currentTime, {int length: 6, int interval: 30, Algorithm algorithm: Algorithm.SHA256, bool isGoogle: false})\n\nGenerate a code for the provided secret and time.\n\n- `secret` - (String) A Base32 String.\n- `currentTime` - (int) The current time in milliseconds.\n- `length` - (int) The length of the resulting code.\n- `interval` - (int) Refresh interval to get a new code.\n- `algorithm` - (Algorithm) Hashing method.\n- `isGoogle` - (bool) flag to turn off secret padding for Google Auth.\n\nReturns an `String` code. Preserves leading zeros.\n\n### OTP.generateHOTPCode(String secret, int counter, {int length: 6})\n\nGenerate a code for the provided secret and time.\n\n- `secret` - (String) A Base32 String.\n- `counter` - (int) An int counter.\n- `length` - (int) the length of the resulting code.\n\nReturns an `int` code. Does not preserve leading zeros\n\n### OTP.generateHOTPCodeString(String secret, int counter, {int length: 6})\n\nGenerate a code for the provided secret and time.\n\n- `secret` - (String) A Base32 String.\n- `counter` - (int) An int counter.\n- `length` - (int) the length of the resulting code.\n\nReturns an `String` code. Preserves leading zeros\n\n### OTP.constantTimeVerification(final String code, final String othercode)\n\n*!DISCLAIMER!*\nI can only get this to be within 1 millisecond between different codes and same codes.\nI have yet to get them to be equal. but 1 millisecond should be an OK room for error though.\n\nCompares 2 codes in constant time to minimize risk of timing attacks.\n\n- `code` - (String) A Base32 String.\n- `othercode` - (String) A Base32 String.\n\nReturns an `bool` if they match or not.\n\n### OTP.remainingSeconds({int interval = 30})\n\nThis will return the remaining seconds based on the `lastUsedTime` variable, that is only set when using `generateTOTP*` functions.\n\n- `interval` - (int) The interval you are using for your codes, defaults to the standard 30 seconds.\n\nReturns an `int` of the remaining seconds.\n\n## Testing\n\n```\npub run test\n```\n\n## Release notes\n\nSee CHANGELOG.md\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaegalus%2Fdart-otp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaegalus%2Fdart-otp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaegalus%2Fdart-otp/lists"}