{"id":26102459,"url":"https://github.com/azozzalfiras/2fa-google","last_synced_at":"2026-06-01T04:01:32.893Z","repository":{"id":281486602,"uuid":"945433345","full_name":"AzozzALFiras/2FA-Google","owner":"AzozzALFiras","description":"This PHP package offers an easy implementation of Google 2FA using the TOTP algorithm, allowing you to generate and verify OTPs, as well as create QR codes for authentication setup.","archived":false,"fork":false,"pushed_at":"2025-03-09T12:17:41.000Z","size":5,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-19T12:28:24.193Z","etag":null,"topics":["2fa","2fa-generator","2fa-php","2fa-security","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AzozzALFiras.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-03-09T12:15:09.000Z","updated_at":"2025-04-16T09:00:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"3be4b981-9c5a-4b42-a3b6-6035e243ccde","html_url":"https://github.com/AzozzALFiras/2FA-Google","commit_stats":null,"previous_names":["azozzalfiras/2fa-google"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AzozzALFiras/2FA-Google","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AzozzALFiras%2F2FA-Google","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AzozzALFiras%2F2FA-Google/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AzozzALFiras%2F2FA-Google/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AzozzALFiras%2F2FA-Google/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AzozzALFiras","download_url":"https://codeload.github.com/AzozzALFiras/2FA-Google/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AzozzALFiras%2F2FA-Google/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33759178,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-01T02:00:06.963Z","response_time":115,"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","2fa-generator","2fa-php","2fa-security","php"],"created_at":"2025-03-09T19:41:42.202Z","updated_at":"2026-06-01T04:01:32.881Z","avatar_url":"https://github.com/AzozzALFiras.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AzozzAlfiras 2FA Google - PHP Package\n\nThis PHP package provides a simple implementation for Google 2-Factor Authentication (2FA) using the Time-based One-Time Password (TOTP) algorithm. It includes functionalities for generating OTPs, verifying OTPs, and creating QR codes for authentication setup.\n\n## Installation\n\nYou can install this package via Composer:\n\n```bash\ncomposer require azozzalfiras/2fa-google\n```\n\n## Usage\n\n### Setup and Configuration\n\nTo use this package, instantiate the `TwoFactorAuth` class with the secret key, user, and issuer. Optionally, you can customize the user and issuer values.\n\n```php\n\u003c?php\n\nuse AzozzAlfiras\\TwoFactorAuth\\TwoFactorAuth;\n\n// Create a new instance of TwoFactorAuth without passing email and issuer initially\n$twoFactorAuth = new TwoFactorAuth();  // Constructor does not require parameters anymore\n\n// Generate or get the secret key externally (e.g., stored or retrieved from a database)\n$generatedSecretKey = $twoFactorAuth-\u003egetSecretKey();  // This will get the generated secret key\n\n// Initialize the object with secretKey, email, and issuer\n$twoFactorAuth-\u003einitialize($generatedSecretKey, 'user@example.com', 'MyAppIssuer');\n\n// Generate the QR code URL\n$qrCodeUrl = $twoFactorAuth-\u003egenerateQrCodeUrl();\necho \"QR Code URL: \" . $qrCodeUrl . \"\\n\";\n```\n\n### Step-by-step Usage\n\nTo use the `Otp` class from the **AzozzAlfiras\\TwoFactorAuth** namespace, follow these steps:\n\n1. **Instantiate the Otp Class**: First, you need to create an instance of the `Otp` class. This class requires the secret key (Base32 encoded) as a parameter.\n2. **Generate OTP**: Use the `generateOtp()` method to generate a one-time password (OTP) based on the provided secret key.\n3. **Verify OTP**: Use the `verifyOtp()` method to verify if the entered OTP matches the generated OTP.\n4. **Generate QR Code URL**: Use the `generateQrCodeUrl()` method to generate the URL needed to generate the QR code for Google Authenticator.\n\n## Features\n\n- **Instantiate the Otp Class**: Create an instance of the `Otp` class with the secret key.\n- **Generate OTP**: Generate a one-time password using the `generateOtp()` method.\n- **Verify OTP**: Verify the OTP using the `verifyOtp()` method.\n- **Generate QR Code URL**: Generate the URL for the QR code using the `generateQrCodeUrl()` method.\n\n## Example Usage\n\n```php\n\u003c?php\n\nrequire 'vendor/autoload.php'; // Include Composer autoload if you're using Composer\n\nuse AzozzAlfiras\\TwoFactorAuth\\Otp;\n\n// Define the secret key (Base32 encoded secret)\n$secretKey = ''; // get the secretKey from .env  \n\n// Create an instance of the Otp class\n$otp = new Otp($secretKey);\n\n// Generate OTP\n$generatedOtp = $otp-\u003egenerateOtp();\necho \"Generated OTP: \" . $generatedOtp . \"\\n\";\n\n// Verify the OTP (for example, entered by the user)\n$enteredOtp = '123456';  // Replace with the OTP entered by the user\n$isVerified = $otp-\u003everifyOtp($enteredOtp);\n\nif ($isVerified) {\n    echo \"OTP is valid!\\n\";\n} else {\n    echo \"Invalid OTP!\\n\";\n}\n?\u003e\n```\n\n## Explanation\n\n- **Instantiate Otp**: The `Otp` class requires a Base32 encoded secret key. This secret key can be generated using the `TwoFactorAuth` class and is used to generate and verify OTPs.\n- **Generate OTP**: The `generateOtp()` method calculates a one-time password based on the current time and the secret key.\n- **Verify OTP**: The `verifyOtp()` method compares the OTP entered by the user with the generated OTP to confirm its validity.\n- **Generate QR Code URL**: The `generateQrCodeUrl()` method provides a URL that can be used to generate a QR code for the user to scan using Google Authenticator or another authenticator app.\n\n## License\n\nThis package is open-source and available under the MIT License.\n\n### Key Highlights\n\n- Sections like **Installation**, **Usage**, **Features**, and **Example Usage** are clearly defined with headers.\n- Code examples are surrounded by triple backticks (```), making it easy to copy and understand.\n- The **Step-by-step Usage** section explains each part of the process clearly.\n- The **Features** section outlines the key functionalities of the package.\n\nThis `README.md` should provide everything needed for a user to understand, install, and use the package effectively.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazozzalfiras%2F2fa-google","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazozzalfiras%2F2fa-google","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazozzalfiras%2F2fa-google/lists"}