{"id":16101729,"url":"https://github.com/kelunik/two-factor","last_synced_at":"2025-03-16T08:32:30.679Z","repository":{"id":49269937,"uuid":"56076388","full_name":"kelunik/two-factor","owner":"kelunik","description":"Two factor authentication.","archived":false,"fork":false,"pushed_at":"2021-06-21T18:49:33.000Z","size":22,"stargazers_count":37,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-12T01:05:25.299Z","etag":null,"topics":["2fa","google-authenticator","oath-hotp","oath-totp","two-factor"],"latest_commit_sha":null,"homepage":null,"language":"PHP","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/kelunik.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":"2016-04-12T15:42:24.000Z","updated_at":"2025-01-03T09:50:56.000Z","dependencies_parsed_at":"2022-08-21T13:50:51.784Z","dependency_job_id":null,"html_url":"https://github.com/kelunik/two-factor","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kelunik%2Ftwo-factor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kelunik%2Ftwo-factor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kelunik%2Ftwo-factor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kelunik%2Ftwo-factor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kelunik","download_url":"https://codeload.github.com/kelunik/two-factor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243806070,"owners_count":20350775,"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":["2fa","google-authenticator","oath-hotp","oath-totp","two-factor"],"created_at":"2024-10-09T18:50:49.615Z","updated_at":"2025-03-16T08:32:30.344Z","avatar_url":"https://github.com/kelunik.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# two-factor\n\n[![Build Status](https://img.shields.io/travis/kelunik/two-factor/master.svg?style=flat-square)](https://travis-ci.org/kelunik/two-factor)\n[![CoverageStatus](https://img.shields.io/coveralls/kelunik/two-factor/master.svg?style=flat-square)](https://coveralls.io/github/kelunik/two-factor?branch=master)\n![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)\n\n`kelunik/two-factor` is a Google Authenticator compatible OATH implementation.\n\n## Requirements\n\n- PHP 5.5+\n\n## Installation\n\n```bash\ncomposer require kelunik/two-factor\n```\n\n## Demo\n\nThere's a [runnable demo](./examples/demo.php) contained in this repository.\n\n## Usage\n\n### Generate a secret per user\n\n```php\n$oath = new Oath;\n\n// this generates a key in binary format\n$key = $oath-\u003egenerateKey();\n\n// store key for user\n```\n\n### Let user setup two factor device\n\n```php\n$oath = new Oath;\n$key = \"...\"; // load user key from storage\n\n// Use the URI to provide an easy to scan QR code\n$uri = $oath-\u003egetUri($key);\n\n// Alternatively display the key for manual input\n$secret = $oath-\u003eencodeKey($key);\n```\n\nYou can use your favourite JavaScript or PHP library to generate the QR code. For a working example, we're using [`qr.js`](http://neocotic.com/qr.js/).\n\n```html\n\u003cform action=\"/2fa/setup\" method=\"POST\"\u003e\n    Scan the following QR code and click continue once you're ready.\n    \u003cinput type=\"hidden\" value=\"{{$uri}}\" id=\"2fa-uri\"\u003e\n\n    \u003ccanvas id=\"qr-code\"\u003e\u003c/canvas\u003e\n    \u003cscript src=\"/js/qr.min.js\"\u003e\u003c/script\u003e\n    \u003cscript\u003e\n        qr.canvas({\n            canvas: document.getElementById(\"qr-code\"),\n            value: document.getElementById(\"2fa-uri\").value\n        });\n    \u003c/script\u003e\n\n    \u003cbutton type=\"submit\"\u003eContinue\u003c/button\u003e\n\u003c/form\u003e\n```\n\n### Validate TOTP value\n\n```php\n$oath = new Oath;\n$key = \"...\"; // load user key from storage\n$isValid = $oath-\u003everifyTotp($key, $totpValue);\n// If the token is valid, ensure that it can't be used again.\n// Because we use the default grace window size of two,\n// we have to store the used TOTP value for at least 90 seconds,\n// to prevent its usage explicitly.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkelunik%2Ftwo-factor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkelunik%2Ftwo-factor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkelunik%2Ftwo-factor/lists"}