{"id":27055578,"url":"https://github.com/ja7ad/otp","last_synced_at":"2025-09-06T20:32:18.519Z","repository":{"id":285931088,"uuid":"959639219","full_name":"ja7ad/otp","owner":"ja7ad","description":"A high-performance, zero-dependency Go package for generating and validating TOTP, HOTP and OCRA one-time passwords — RFC 4226, RFC 6238 and RFC 6287 compliant.","archived":false,"fork":false,"pushed_at":"2025-05-11T17:57:18.000Z","size":3137,"stargazers_count":34,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-01T00:30:42.268Z","etag":null,"topics":["2fa","authentication","go","golang","hotp","mfa","otp","rfc4226","rfc6238","rfc6287","security","totp"],"latest_commit_sha":null,"homepage":"","language":"Go","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/ja7ad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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,"zenodo":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":null,"thanks_dev":null,"custom":["https://javad.dev/support"]}},"created_at":"2025-04-03T05:42:36.000Z","updated_at":"2025-07-09T16:18:06.000Z","dependencies_parsed_at":"2025-04-09T19:13:19.824Z","dependency_job_id":"a3e9a5b7-8e9b-4399-acc0-5e68dfbc7f97","html_url":"https://github.com/ja7ad/otp","commit_stats":null,"previous_names":["ja7ad/otp"],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/ja7ad/otp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ja7ad%2Fotp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ja7ad%2Fotp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ja7ad%2Fotp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ja7ad%2Fotp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ja7ad","download_url":"https://codeload.github.com/ja7ad/otp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ja7ad%2Fotp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273958482,"owners_count":25198059,"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","status":"online","status_checked_at":"2025-09-06T02:00:13.247Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["2fa","authentication","go","golang","hotp","mfa","otp","rfc4226","rfc6238","rfc6287","security","totp"],"created_at":"2025-04-05T09:28:07.425Z","updated_at":"2025-09-06T20:32:18.510Z","avatar_url":"https://github.com/ja7ad.png","language":"Go","funding_links":["https://javad.dev/support"],"categories":[],"sub_categories":[],"readme":"![otp](.github/otp.svg)\n[![codecov](https://codecov.io/gh/Ja7ad/otp/branch/main/graph/badge.svg?token=8N6N60D5UI)](https://codecov.io/gh/Ja7ad/otp)\n[![Go Report Card](https://goreportcard.com/badge/github.com/ja7ad/otp)](https://goreportcard.com/report/github.com/ja7ad/otp)\n[![Go Reference](https://pkg.go.dev/badge/github.com/ja7ad/otp.svg)](https://pkg.go.dev/github.com/ja7ad/otp)\n\n# 🔐 OTP\n\nA high-performance, zero-dependency Go package for generating and validating TOTP, HOTP and OCRA one-time passwords — RFC [4226](https://datatracker.ietf.org/doc/html/rfc4226), RFC [6238](https://datatracker.ietf.org/doc/html/rfc6238) and RFC [6287](https://datatracker.ietf.org/doc/html/rfc6287) compliant.\n\n\n- [Feature](#-features)\n- [Installation](#-installation-go--124)\n  - [Library](#-using-go)\n  - [OTP-API](#-prebuilt-binary)\n  - [Docker](#-docker-image)\n- [Comparison](#-comparison)\n  - [Performance](#-performance-comparison)\n  - [Features](#-feature-comparison)\n- [Proof algorithm](#-algorithm-rfc)\n- [Usage](#-usage)\n- [Contributing](#-contributing)\n- [Reference](#-references)\n\n## ✨ Features\n\n- Zero dependencies – fully self-contained, no external packages  \n- High performance with low allocations\n- Supports HOTP (RFC [4226](https://datatracker.ietf.org/doc/html/rfc4226)), TOTP (RFC [6238](https://datatracker.ietf.org/doc/html/rfc6238)) and OCRA (RFC [6287](https://datatracker.ietf.org/doc/html/rfc6287)) algorithms  \n- Configurable OTP digit lengths: 6, 8, or 10  \n- Supports SHA1, SHA256, and SHA512 HMAC algorithms  \n- Constant-time OTP validation to prevent timing attacks  \n- Clock skew tolerance for TOTP validation  \n- Generates `otpauth://` URLs for Google Authenticator and compatible apps  \n- Parses `otpauth://` URLs into configuration structs  \n- Secure random secret generation (base32 encoded)  \n- Thoroughly tested against official RFC test vectors  \n- Includes fuzz tests, benchmark coverage, and solid algorithm validation\n\nHere’s your updated `README.md` **Installation** section with release and Docker image info:\n\n\n## 📦 Installation (Go \u003e= 1.24)\n\n### 🛠️ Using Go\n\n```bash\ngo get -u github.com/ja7ad/otp\n```\n\n\u003e Node.js bindings are available [here](./otp-js).\n\n---\n\n### 🚀 Prebuilt Binary\n\nDownload the latest CLI/API binary for your platform from the [latest release page](https://github.com/ja7ad/otp/releases/latest).\n\n\u003e Online demo: https://otp-api.leapcell.app/docs\n\n```shell\n$ otp -serve localhost:8080\n2025/04/06 10:41:48 INFO starting server address=:8080\n2025/04/06 10:41:50 INFO request method=GET path=/docs/index.html status=200 duration=740.394µs\n2025/04/06 10:41:51 INFO request method=GET path=/docs/doc.json status=200 duration=803.67µs\n2025/04/06 10:41:53 INFO request method=GET path=/ status=200 duration=149.042µs\n2025/04/06 10:41:54 INFO request method=GET path=/docs status=302 duration=24.444µs\n```\n\n| Method | Path               | Description                      |\n|--------|--------------------|----------------------------------|\n| POST   | `/totp/generate`   | Generate a TOTP code             |\n| POST   | `/totp/validate`   | Validate a TOTP code             |\n| POST   | `/hotp/generate`   | Generate a HOTP code             |\n| POST   | `/hotp/validate`   | Validate a HOTP code             |\n| POST   | `/ocra/generate`   | Generate an OCRA code            |\n| POST   | `/ocra/validate`   | Validate an OCRA code            |\n| GET    | `/otp/secret`      | Generate a random base32 secret  |\n| POST   | `/otp/url`         | Generate otpauth URL             |\n| GET    | `/ocra/suites`     | List supported OCRA suites       |\n| POST   | `/ocra/suite`      | Parse and describe suite config  |\n\n---\n\n### 🐳 Docker Image\n\nYou can also run the server using Docker:\n\n```bash\ndocker pull ja7adr/otp\ndocker run -p 8080:8080 ja7adr/otp\n```\n\n\u003e Image available at [Docker Hub](https://hub.docker.com/r/ja7adr/otp)\n\n## 🔬 Comparison\n\nThis comparison is performance and feature.\n\n#### 🚀 Performance Comparison\n\nThis comparison is for `Ja7ad/otp` vs `pquerna/otp`\n\n| Algorithm | Suite                                | Digits | Library        | `ns/op` | `B/op` | `allocs/op` | `N` (runs/sec) |\n|-----------|----------------------------------------|--------|----------------|---------|--------|--------------|----------------|\n| SHA1      | `OCRA-1:HOTP-SHA1-6:QN08`              | 6      | **Ja7ad/otp**  | **1134**    | **552**   | **9**         | **881,058**    |\n| SHA1      | HOTP/TOTP (default)                    | 6      | pquerna/otp    | 1420    | 592    | 13           | 704,225        |\n| SHA256    | `OCRA-1:HOTP-SHA256-8:C-QN08-PSHA1`    | 8      | **Ja7ad/otp**  | **984.3**   | **592**   | **9**         | **1,015,907**  |\n| SHA256    | HOTP/TOTP (default)                    | 8      | pquerna/otp    | 1477    | 728    | 13           | 677,236        |\n| SHA512    | `OCRA-1:HOTP-SHA512-8:QN08-T1M`        | 8      | **Ja7ad/otp**  | **1752**    | **944**   | **9**         | **570,853**    |\n| SHA512    | HOTP/TOTP (default)                    | 8      | pquerna/otp    | 2359    | 1224   | 13           | 423,778        |\n\n\n| Metric            | Ja7ad/otp           | pquerna/otp        | ✅ Winner |\n|------------------|---------------------|---------------------|----------|\n| **Execution time** (`ns/op`) | **~2x faster** across all algorithms and digit sizes | Slower in all cases | ✅ **Ja7ad/otp** |\n| **Memory usage** (`B/op`) | **~30–50% less** memory allocated | Higher allocations | ✅ **Ja7ad/otp** |\n| **Allocations** (`allocs/op`) | **7** allocations | **13** allocations | ✅ **Ja7ad/otp** |\n| **Dependencies**  | **Zero** external deps | Relies on stdlib + extras | ✅ **Ja7ad/otp** |\n\n- `Ja7ad/otp`: **736 ns**, **520 B**, **7 allocs**\n- `pquerna/otp`: **1495 ns**, **728 B**, **13 allocs**\n\n#### ✅ Feature Comparison\n\n| Feature                     | Ja7ad/otp | pquerna/otp |\n|-----------------------------|-----------|-------------|\n| RFC 4226 HOTP               | ✅        | ✅          |\n| RFC 6238 TOTP               | ✅        | ✅          |\n| RFC 6287 OCRA               | ✅        | ❌          |\n| Built-in OCRA Suite Configs | ✅        | ❌          |\n| Full RFC Test Vector Suite | ✅        | ❌          |\n| Constant-Time Validation    | ✅        | ✅          |\n| Cross-platform Friendly     | ✅        | ✅          |\n| Zero Dependency Core        | ✅        | ❌ (uses crypto/rand + external parsing) |\n\n\n## 📑 Algorithm (RFC)\n\n- [RFC 4226 / 6238](docs/rfc4226.md) proof algorithm\n- [RFC 6287](docs/rfc6287.md) proof algorithm\n\n## 📚 Usage\n\n\n\u003cdetails\u003e\u003csummary\u003eTOTP example\u003c/summary\u003e\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/ja7ad/otp\"\n\t\"log\"\n\t\"time\"\n)\n\nfunc main() {\n\tsecret, err := otp.RandomSecret(otp.SHA1)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tt := time.Now()\n\n\tcode, err := otp.GenerateTOTP(secret, t, otp.DefaultTOTPParam)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tfmt.Println(code)\n\n\tok, err := otp.ValidateTOTP(secret, code, t, otp.DefaultTOTPParam)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tif !ok {\n\t\tlog.Fatal(\"Invalid OTP\")\n\t}\n\n\turl, err := otp.GenerateTOTPURL(otp.URLParam{\n\t\tIssuer:      \"https://example.com\",\n\t\tSecret:      secret,\n\t\tAccountName: \"foobar\",\n\t\tPeriod:      otp.DefaultTOTPParam.Period,\n\t\tDigits:      otp.DefaultTOTPParam.Digits,\n\t\tAlgorithm:   otp.DefaultTOTPParam.Algorithm,\n\t})\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tfmt.Println(url.String())\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eHOTP example code\u003c/summary\u003e\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/ja7ad/otp\"\n\t\"log\"\n)\n\nfunc main() {\n\tsecret, err := otp.RandomSecret(otp.SHA1)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tcounter := uint64(1)\n\n\tcode, err := otp.GenerateHOTP(secret, counter, otp.DefaultHOTPParam)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tfmt.Println(code)\n\n\tok, err := otp.ValidateHOTP(secret, code, counter, otp.DefaultHOTPParam)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tif !ok {\n\t\tlog.Fatal(\"Invalid OTP\")\n\t}\n\n\turl, err := otp.GenerateHOTPURL(otp.URLParam{\n\t\tIssuer:      \"https://example.com\",\n\t\tSecret:      secret,\n\t\tAccountName: \"foobar\",\n\t\tPeriod:      otp.DefaultHOTPParam.Period,\n\t\tDigits:      otp.DefaultHOTPParam.Digits,\n\t\tAlgorithm:   otp.DefaultHOTPParam.Algorithm,\n\t})\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tfmt.Println(url.String())\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eOCRA example code\u003c/summary\u003e\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/ja7ad/otp\"\n)\n\nfunc main() {\n\tsecret, err := otp.RandomSecret(otp.SHA1)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tsuite := otp.MustRawSuite(\"OCRA-1:HOTP-SHA1-6:QN08\")\n\n\tcode, err := otp.GenerateOCRA(secret, suite, otp.OCRAInput{\n\t\tChallenge: []byte(\"12345678\"),\n\t})\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tok, err := otp.ValidateOCRA(secret, code, suite, otp.OCRAInput{\n\t\tChallenge: []byte(\"12345678\"),\n\t})\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(ok)\n}\n```\n\n\u003c/details\u003e\n\n## 🤝 Contributing\n\nWe welcome contributions of all kinds — from fixing bugs and improving documentation to implementing new RFCs.\n\nPlease read our [Contributing Guide](CONTRIBUTING.md) to get started. It includes setup instructions, coding standards, and development workflows.\n\nWhether you're filing an issue, submitting a pull request, or suggesting an improvement — thank you for helping make this library better! 🙌\n\n\n\n## 📖 References\n\n- [RFC 6287 - OCRA](https://datatracker.ietf.org/doc/html/rfc6287)\n- [RFC 4226 - HOTP](https://datatracker.ietf.org/doc/html/rfc4226)\n- [RFC 6238 - TOTP](https://datatracker.ietf.org/doc/html/rfc6238)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fja7ad%2Fotp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fja7ad%2Fotp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fja7ad%2Fotp/lists"}