{"id":24901937,"url":"https://github.com/lancegin/jsotp","last_synced_at":"2025-10-24T23:31:35.756Z","repository":{"id":49849829,"uuid":"95526825","full_name":"LanceGin/jsotp","owner":"LanceGin","description":"Javascript One-Time Password module.","archived":false,"fork":false,"pushed_at":"2021-05-31T02:16:55.000Z","size":94,"stargazers_count":95,"open_issues_count":1,"forks_count":15,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-01T21:18:52.307Z","etag":null,"topics":["base32","hotp","one-time-passwords","otp","rfc-4226","rfc-6238","totp"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/LanceGin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-27T06:49:17.000Z","updated_at":"2024-12-15T07:15:32.000Z","dependencies_parsed_at":"2022-08-29T04:52:06.017Z","dependency_job_id":null,"html_url":"https://github.com/LanceGin/jsotp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LanceGin%2Fjsotp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LanceGin%2Fjsotp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LanceGin%2Fjsotp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LanceGin%2Fjsotp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LanceGin","download_url":"https://codeload.github.com/LanceGin/jsotp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238044093,"owners_count":19407128,"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":["base32","hotp","one-time-passwords","otp","rfc-4226","rfc-6238","totp"],"created_at":"2025-02-01T21:18:48.256Z","updated_at":"2025-10-24T23:31:35.382Z","avatar_url":"https://github.com/LanceGin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jsotp\n\n`jsotp` is a node module 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.\n\nThe module was implement based on [RFC4226](https://tools.ietf.org/html/rfc4226) (HOTP: An HMAC-Based One-Time Password Algorithm) and [RFC6238](https://tools.ietf.org/html/rfc6238) (TOTP: Time-Based One-Time Password Algorithm)\n\n### Example\n\n![](http://wx4.sinaimg.cn/large/89243dfbgy1fh3bz5e8bkj20rs0go460.jpg)\n\n### Feature\n\n* Generate random base32 encoded string\n* Generate a `otpauth url` with the b32 encoded string\n* Create a HOTP object with verification\n* Verify a HOTP token\n* Create a TOTP object with verification\n* Verify a TOTP token\n\n### Installation\n\n```shell\nnpm install jsotp\n```\n\t\n### Module\n\nAll modules support:\n\n```javascript\nconst jsotp = require('jsotp');\n```\n\t\n### Usage\n\n#### Time-based OTPs\n\n```javascript\n// import\nconst jsotp = require('jsotp');\n\n// Create TOTP object\nconst totp = jsotp.TOTP('BASE32ENCODEDSECRET');\ntotp.now(); // =\u003e 432143\n\n// Verify for current time\ntotp.verify(432143); // =\u003e true\n\n// Verify after 30s\ntotp.verify(432143); // =\u003e false\n```\n\n#### Counter-based OTPs\n\n```javascript\n// import\nconst jsotp = require('jsotp');\n\n// Create HOTP object\nconst hotp = jsotp.HOTP('BASE32ENCODEDSECRET');\nhotp.at(0); // =\u003e 432143\nhotp.at(1); // =\u003e 231434\nhotp.at(2132); // =\u003e 242432\n\n// Verify with a counter\nhotp.verify(242432, 2132); // =\u003e true\nhotp.verify(242432, 2133); // =\u003e false\n```\n\n#### Generate random base32 encoded secret\n\n```javascript\n// import\nconst jsotp = require('jsotp');\n\n// Generate\nconst b32_secret = jsotp.Base32.random_gen();\n```\n\n### Api\n\n#### • [jsotp.Base32.random_gen(length)](https://github.com/LanceGin/jsotp/blob/master/src/base32.js#L32)\n\n\tparam: length\n\ttype: int\n\tdefault: 16\n\treturn: String\n\tdesc: the length of random base32 encoded string.\n\n#### • [jsotp.TOTP(secret)](https://github.com/LanceGin/jsotp/blob/master/src/jsotp.js#L48)\n\t\n\tparam: secret\n\ttype: string\n\treturn: TOTP\n\tdesc: generate TOTP instance.\n\t\n#### • [jsotp.TOTP.now()](https://github.com/LanceGin/jsotp/blob/master/src/totp.js#L38)\n\t\n\treturn: String\n\tdesc: get the one-time password with current time.\n\n#### • [jsotp.TOTP.verify(totp)](https://github.com/LanceGin/jsotp/blob/master/src/totp.js#L70)\n\n\tparam: totp\n\ttype: string\n\treturn: Boolean\n\tdesc: verify the totp code.\n\t\n#### • [jsotp.TOTP.url_gen(issuer)](https://github.com/LanceGin/jsotp/blob/master/src/totp.js#L94)\n\n\tparam: issuer\n\ttype: string\n\treturn: string\n\tdesc: generate url with TOTP instance\n\n#### • [jsotp.HOTP(secret)](https://github.com/LanceGin/jsotp/blob/master/src/jsotp.js#L47)\n\t\n\tparam: secret\n\ttype: string\n\treturn: HOTP\n\tdesc: generate HOTP instance.\n\t\n#### • [jsotp.HOTP.at(counter)](https://github.com/LanceGin/jsotp/blob/master/src/hotp.js#L24)\n\n\tparam: counter\n\ttype: int\n\treturn: String\n\tdesc: generate one-time password with counter.\n\n#### • [jsotp.HOTP.verify(hotp, count)](https://github.com/LanceGin/jsotp/blob/master/src/hotp.js#L50)\n\t\n\tparam: hotp\n\ttype: string\n\tparam: count\n\ttype: int\n\treturn: Boolean\n\tdesc: verify the hotp code.\n\n#### • [jsotp.HOTP.url_gen(issuer)](https://github.com/LanceGin/jsotp/blob/master/src/hotp.js#L69)\n\n\tparam: issuer\n\ttype: string\n\treturn: string\n\tdesc: generate url with HOTP instance\n\n### Contribute\n\n* Clone repo and install dependencies\n\n```shell\ngit clone git@github.com:LanceGin/jsotp.git\nnpm install\n```\n\n* Contribute the code in `src/`, and run command below to build the es6 code to es2015. That will create a local directory named `lib/`.\n\n```shell\nnpm run build\n```\n\n* Unit test\n\n```shell\nnpm test\n```\n\n### [中文文档](docs/README_zh.md)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flancegin%2Fjsotp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flancegin%2Fjsotp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flancegin%2Fjsotp/lists"}