{"id":16464503,"url":"https://github.com/deatil/zig-totp","last_synced_at":"2025-02-27T12:37:39.376Z","repository":{"id":212585956,"uuid":"708303399","full_name":"deatil/zig-totp","owner":"deatil","description":"A TOTP and HOTP library for zig.","archived":false,"fork":false,"pushed_at":"2025-02-16T04:13:56.000Z","size":274,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-16T05:18:34.277Z","etag":null,"topics":["hotp","otp","otp-generator","otp-verification","otpauth","totp","zig","zig-hotp","zig-otp","zig-totp"],"latest_commit_sha":null,"homepage":"https://github.com/deatil/zig-totp","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/deatil.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-22T06:24:40.000Z","updated_at":"2025-02-16T04:13:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"6016e12f-a464-42da-982b-f25f7ea58588","html_url":"https://github.com/deatil/zig-totp","commit_stats":null,"previous_names":["deatil/zig-totp"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deatil%2Fzig-totp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deatil%2Fzig-totp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deatil%2Fzig-totp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deatil%2Fzig-totp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deatil","download_url":"https://codeload.github.com/deatil/zig-totp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241014017,"owners_count":19894182,"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":["hotp","otp","otp-generator","otp-verification","otpauth","totp","zig","zig-hotp","zig-otp","zig-totp"],"created_at":"2024-10-11T11:28:19.251Z","updated_at":"2025-02-27T12:37:39.369Z","avatar_url":"https://github.com/deatil.png","language":"Zig","funding_links":[],"categories":["Libraries","Network \u0026 Web"],"sub_categories":["Web Framework"],"readme":"## Zig-totp \n\nA TOTP and HOTP library for zig.\n\n\n### Why One Time Passwords?\n\nOne Time Passwords (OTPs) are an mechanism to  improve security over passwords alone. When a Time-based OTP (TOTP) is stored on a user's phone, and combined with something the user knows (Password), you have an easy on-ramp to [Multi-factor authentication](http://en.wikipedia.org/wiki/Multi-factor_authentication) without adding a dependency on a SMS provider.  This Password and TOTP combination is used by many popular websites including Google, GitHub, Facebook, Salesforce and many others.\n\nThe `zig-totp` library enables you to easily add TOTPs to your own application, increasing your user's security against mass-password breaches and malware.\n\nBecause TOTP is standardized and widely deployed, there are many [mobile clients and software implementations](http://en.wikipedia.org/wiki/Time-based_One-time_Password_Algorithm#Client_implementations).\n\n\n### Env\n\n - Zig \u003e= 0.14.0-dev.2851+b074fb7dd\n\n\n### Adding zig-totp as a dependency\n\nAdd the dependency to your project:\n\n```sh\nzig fetch --save=zig-totp git+https://github.com/deatil/zig-totp#main\n```\n\nor use local path to add dependency at `build.zig.zon` file\n\n```zig\n.{\n    .dependencies = .{\n        .@\"zig-totp\" = .{\n            .path = \"./lib/zig-totp\",\n        },\n        ...\n    }\n}\n```\n\nAnd the following to your `build.zig` file:\n\n```zig\nconst zig_totp_dep = b.dependency(\"zig-totp\", .{});\nexe.root_module.addImport(\"zig-totp\", zig_totp_dep.module(\"zig-totp\"));\n```\n\nThe `zig-totp` structure can be imported in your application with:\n\n```zig\nconst zig_totp = @import(\"zig-totp\");\n```\n\n\n### Get Starting\n\n~~~zig\nconst std = @import(\"std\");\nconst totp = @import(\"zig-totp\");\n\npub fn main() !void {\n    const alloc = std.heap.page_allocator;\n\n    const secret = \"GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ\";\n    const n = totp.time.now().utc();\n    const passcode = try totp.generateCode(alloc, secret, n);\n    \n    // output: \n    // generateCode: 906939\n    std.debug.print(\"generateCode: {s} \\n\", .{passcode});\n\n    const valid = totp.validate(alloc, passcode, secret);\n    \n    // output: \n    // validate: true\n    std.debug.print(\"validate: {} \\n\", .{valid});\n}\n~~~\n\n\n### Generate keyurl\n\n~~~zig\nconst std = @import(\"std\");\nconst totp = @import(\"zig-totp\");\n\npub fn main() !void {\n    const alloc = std.heap.page_allocator;\n\n    const secret = \"test-data\";\n\n    var key = try totp.generate(alloc, .{\n        .issuer = \"Example\",\n        .account_name = \"accountName\",\n        .period = 30,\n        // .secret_size = 20,\n        // use secret if secret not empty, or use secret_size to generate secret\n        .secret = secret,\n        .digits = .Six,\n        .algorithm = .SHA1,\n    });\n\n    const keyurl = key.urlString();\n    \n    // output: \n    // keyurl: otpauth://totp/Example:accountName?issuer=Example\u0026period=30\u0026digits=6\u0026secret=ORSXG5BNMRQXIYI\u0026algorithm=SHA1\n    std.debug.print(\"keyurl: {} \\n\", .{keyurl});\n}\n~~~\n\n\n### LICENSE\n\n*  The library LICENSE is `Apache2`, using the library need keep the LICENSE.\n\n\n### Copyright\n\n*  Copyright deatil(https://github.com/deatil).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeatil%2Fzig-totp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeatil%2Fzig-totp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeatil%2Fzig-totp/lists"}