{"id":17117072,"url":"https://github.com/enygma/gauth","last_synced_at":"2025-06-20T10:36:19.653Z","repository":{"id":6257019,"uuid":"7489755","full_name":"enygma/gauth","owner":"enygma","description":"Google Authenticator Code Validation and Generation","archived":false,"fork":false,"pushed_at":"2017-11-14T11:46:14.000Z","size":18,"stargazers_count":75,"open_issues_count":2,"forks_count":12,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-14T15:08:26.746Z","etag":null,"topics":["gauth","google-authenticator","php"],"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/enygma.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":"2013-01-07T20:58:20.000Z","updated_at":"2024-04-02T18:58:13.000Z","dependencies_parsed_at":"2022-09-13T00:02:46.943Z","dependency_job_id":null,"html_url":"https://github.com/enygma/gauth","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/enygma%2Fgauth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enygma%2Fgauth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enygma%2Fgauth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enygma%2Fgauth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/enygma","download_url":"https://codeload.github.com/enygma/gauth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250536436,"owners_count":21446732,"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":["gauth","google-authenticator","php"],"created_at":"2024-10-14T17:50:31.800Z","updated_at":"2025-04-24T00:23:35.042Z","avatar_url":"https://github.com/enygma.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"GAuth : Google Authenticator Code Generator/Validation\n=========================\n\n[![Total Downloads](https://img.shields.io/packagist/dt/enygma/gauth.svg?style=flat-square)](https://packagist.org/packages/enygma/gauth)\n\nThe `GAuth` library is designed to generate and validate codes compatible with the\nGoogle Authenticator tools.\n\n### Installation via Composer:\n\nInclude in your `composer.json` file:\n\n```\n{\n    \"require\": {\n        \"enygma/gauth\": \"dev-master\"\n    }\n}\n```\n\n#### Getting Started\n\nTo get started using the Google Authenticator with your application, you'll need to make an\ninitialization key (using `generateCode`) and save that to your app's settings. This is the\ncode you'll share with your users when they're trying to set up their client for your system.\n\nThen, when they log in you have them enter in the latest code listed for your application for\nthier account.\n\n**NOTE:** This tool offers a \"window of opportunity\" for the codes of 2 seconds forward and\nbackward of the current timestamp, just in case things are a bit off. You can change this with\nthe `setRange` method:\n\n```php\n\u003c?php\n$g = new \\GAuth\\Auth();\n\n// set it to 3 seconds\n$g-\u003esetRange(3);\n?\u003e\n```\n\n#### To generate a new code:\n\n```php\n\u003c?php\n\nrequire_once 'vendor/autoload.php';\n\n// Useful for creating a new Initialization key if needed\n$g = new \\GAuth\\Auth();\n$code = $g-\u003egenerateCode();\nvar_dump($code);\n\n?\u003e\n```\n\n#### To validate a code\n\n```php\n\u003c?php\n\n$code = 'code-inputted-from-user';\n\n$g = new \\GAuth\\Auth('your-initialization-code');\n$verify = $g-\u003evalidateCode($code);\n\nif ($verify == true) {\n    echo 'User code verified!';\n} else {\n    echo 'User code invalid!';\n}\n?\u003e\n```\n\n#### To get the QR code for the application\n\nYou can also use the tool to get the URL for a QR code users can scan to add your application to their Authenticator client. The call to `generateQrImage` returns the actual image data for you to use as you wish, either to embed in an `img` tag or save to a file:\n\n```php\n\u003c?php\n$holder = 'foo@bar.com';\n$name = 'my-app-name';\n\n$g = new \\GAuth\\Auth('your-initialization-code');\n$qrCodeImageData = $g-\u003egenerateQrImage($holder, $name, 200);\n\n// To use in an image tag:\necho '\u003cimg src=\"data:image/png;base64,'.base64_encode($qrCodeImageData).'\"/\u003e\u003cbr/\u003e\u003chr/\u003e';\n\n// Or just save to a file\nfile_put_contents('/path/to/qr-file.png', $qrCodeImageData);\n?\u003e\n```\n\nThe library uses internal QR code generation, not the Google Charts API many similar libraries use.\n\n\n#### More info:\n\n- [Google TOTP Two-factor Authentication for PHP](http://www.idontplaydarts.com/2011/07/google-totp-two-factor-authentication-for-php/)\n- [Links to client for smartphones](http://support.google.com/accounts/bin/answer.py?hl=en\u0026answer=1066447)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenygma%2Fgauth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fenygma%2Fgauth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenygma%2Fgauth/lists"}