mincdev / php-otpauth
A library for genrating a 2 factor authentication QR code
Installs: 12 293
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- tecnickcom/tc-lib-barcode: ^1.17
This package is auto-updated.
Last update: 2025-03-22 12:53:24 UTC
README
A library for generating a 2 factor authentication QR code to use with Google Authenticator, Authy, etc.
Secure QRCode Creation
This library has secure QRCode creation because of the fact that the QRCode is generated locally on your server. This means that the user's secret is not passed to any third party or remote server in order to generate a code. This was inspired by the stack overflow answer by kravietz as seen here
Installation (Composer)
composer require mincdev/php-otpauth
Dependencies
This library requires the tc-lib-barcode library found at https://github.com/tecnickcom/tc-lib-barcode.
Note: The tc-lib-barcode library is maintained and owned by a separate entity.
Generating a QR Code
You can generate a QR code which can be scanned by Google Authenticator, Authy, etc. by using the below.
$otpAuth = new OtpAuthenticator(); $userName = "MrDoe"; $appName = "My Awesome App"; // Store this secret somewhere safe, as you'll need it to validate the pin later $userSecret = $otpAuth->newSecret(); $qrBase64 = $otpAuth->getQR($userName, $appName, $userSecret);
Validating a PIN
Once your user logs in, you can validate their pin by making use of the following:
$otpAuth = new OtpAuthenticator(); $isValid = $otpAuth->validate($userSecret, $pinCode);