jp3cki / totp
RFC 6238 / TOTP: Time-Based One-Time Password Algorithm
Installs: 12 872
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 5
Forks: 0
Open Issues: 0
Requires
- php: >= 8.1
- php-64bit: >= 8.1
- ext-hash: *
- christian-riesen/base32: ^1.6
Requires (Dev)
- ergebnis/composer-normalize: ^2.43
- jp3cki/coding-standard: ^1.0.0
- phpstan/phpstan: ^1.11.5
- phpunit/phpunit: ^10.5.24
- squizlabs/php_codesniffer: ^3.10.1
This package is auto-updated.
Last update: 2024-10-24 03:58:47 UTC
README
PHP implementation of RFC6238 (TOTP: Time-Based One-Time Password Algorithm).
Requirements
- PHP (64-bits): PHP 8.1 or later
- PHP Extensions: hash
Install
- Set up Composer, the de facto standard package manager.
php composer.phar require jp3cki/totp
Usage
<?php declare(strict_types=1); use jp3cki\totp\Totp; require_once('vendor/autoload.php'); // Generate new shared-secret key (for each user) $secret = Totp::generateKey(); echo "secret: {$secret}\n"; echo "\n"; // Make URI for importing from QRCode. $uri = Totp::createKeyUriForGoogleAuthenticator($secret, 'theuser@example.com', 'Issuer Name'); echo "uri: {$uri}\n"; echo "\n"; // Verify user input $userInput = '123456'; // $_POST['totp'] $isValid = Totp::verify($userInput, $secret, time()); var_dump($isValid);
License
Copyright (c) 2015-2024 AIZAWA Hina <hina@fetus.jp>
Contributing
Patches and/or report issues are welcome.
- Please create new branch for each issue or feature. (should not work in master branch)
- Please write and run test.
$ make test
- Please run check-style for static code analysis and coding rule checking.
$ make check-style
- Please clean up commits.
- Please create new pull-request for each issue or feature.
- Please use Japanese or very simple English to create new pull-request or issue.
Breaking Changes
-
v3.0.0
- Minimum environment is now PHP 8.1
-
v2.0.0
- Minimum environment is now PHP 7.2
- Argument types are now strictly enforced
- Removed
Random::generate*()
. Always userandom_bytes()
now.