Skip to content

Commit dba0614

Browse files
committed
1 parent 8d9a37c commit dba0614

14 files changed

Lines changed: 395 additions & 111 deletions

.github/workflows/ci.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ on:
2121
name: "Continuous Integration"
2222

2323
env:
24-
PHP_EXTENSIONS: "" # caution: setting 'none' resets/disables shared extensions
24+
PHP_EXTENSIONS: curl, fileinfo, gd, imagick, json, mbstring, sodium
2525
PHP_INI_VALUES: memory_limit=-1, error_reporting=-1, display_errors=On
2626

2727
jobs:
@@ -38,10 +38,13 @@ jobs:
3838
fail-fast: true
3939
matrix:
4040
php-version:
41+
- "7.4"
42+
- "8.0"
4143
- "8.1"
4244
- "8.2"
4345
- "8.3"
4446
- "8.4"
47+
- "8.5"
4548

4649
steps:
4750
- name: "Checkout"
@@ -56,7 +59,7 @@ jobs:
5659
coverage: none
5760

5861
- name: "Validate composer.json"
59-
run: composer validate --ansi --strict
62+
run: composer validate --no-interaction --ansi --verbose --with-dependencies
6063

6164
- name: "Install dependencies with composer"
6265
uses: ramsey/composer-install@v3
@@ -67,9 +70,6 @@ jobs:
6770
- name: "Run phan"
6871
run: php vendor/bin/phan --target-php-version=${{ matrix.php-version }}
6972

70-
- name: "Run PHPStan"
71-
run: php vendor/bin/phpstan
72-
7373

7474
tests:
7575
name: "Unit Tests"
@@ -83,10 +83,13 @@ jobs:
8383
- ubuntu-latest
8484
- windows-latest
8585
php-version:
86+
- "7.4"
87+
- "8.0"
8688
- "8.1"
8789
- "8.2"
8890
- "8.3"
8991
- "8.4"
92+
- "8.5"
9093

9194
steps:
9295
- name: "Checkout"

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.phan/config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// that functions removed in php 7.0 exist.
1414
// (See `backward_compatibility_checks` for additional options)
1515
'target_php_version' => null,
16-
'minimum_target_php_version' => '8.1',
16+
'minimum_target_php_version' => '7.4',
1717

1818
// A list of directories that should be parsed for class and
1919
// method information. After excluding the directories

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2024 smiley <smiley@chillerlan.net>
3+
Copyright (c) 2026 smiley <smiley@chillerlan.net>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

composer.json

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
{
22
"$schema": "https://getcomposer.org/schema.json",
3-
"name": "chillerlan/php-library-template-nodocs",
4-
"description": "A PHP Library template/boilerplate.",
3+
"name": "chillerlan/2fa-qrcode-bundle",
4+
"description": "An authenticator and a QR Code generator bundled together for MFA in frameworks and applications.",
55
"license": "MIT",
66
"type": "library",
7-
"keywords": ["boilerplate", "library-template"],
7+
"keywords": [
8+
"2fa", "authenticator", "qrcode", "google2fa", "hotp", "mfa",
9+
"otp", "rfc4226", "rfc6238", "tfa", "totp", "two factor"
10+
],
811
"authors": [
912
{
1013
"name": "smiley",
@@ -13,7 +16,7 @@
1316
},
1417
{
1518
"name": "Contributors",
16-
"homepage":"https://github.com/chillerlan/php-library-template-nodocs/graphs/contributors"
19+
"homepage":"https://github.com/chillerlan/2fa-qrcode-bundle/graphs/contributors"
1720
}
1821
],
1922
"funding": [
@@ -22,42 +25,39 @@
2225
"url": "https://ko-fi.com/codemasher"
2326
}
2427
],
25-
"homepage": "https://github.com/chillerlan/php-library-template-nodocs",
28+
"homepage": "https://github.com/chillerlan/2fa-qrcode-bundle",
2629
"support": {
27-
"issues": "https://github.com/chillerlan/php-library-template-nodocs/issues",
28-
"source": "https://github.com/chillerlan/php-library-template-nodocs"
30+
"issues": "https://github.com/chillerlan/2fa-qrcode-bundle/issues",
31+
"source": "https://github.com/chillerlan/2fa-qrcode-bundle"
2932
},
3033
"minimum-stability": "stable",
3134
"prefer-stable": true,
3235
"require": {
33-
"php": "^8.1"
36+
"php": "^7.4 || ^8.0",
37+
"chillerlan/php-authenticator": "^4.5.0",
38+
"chillerlan/php-qrcode": "^5.0.5",
39+
"chillerlan/php-settings-container": "^2.1.6"
3440
},
3541
"require-dev": {
36-
"phan/phan": "^5.5.0",
42+
"phan/phan": "^5.5.2",
3743
"phpmd/phpmd": "^2.15",
38-
"phpstan/phpstan": "^2.1.22",
39-
"phpstan/phpstan-deprecation-rules": "^2.0.3",
40-
"phpunit/phpunit": "^10.5",
41-
"slevomat/coding-standard": "^8.15",
42-
"squizlabs/php_codesniffer": "^3.10"
43-
},
44-
"suggest": {
44+
"phpunit/phpunit": "^9.6",
45+
"slevomat/coding-standard": "^8.28",
46+
"squizlabs/php_codesniffer": "^4.0"
4547
},
4648
"autoload": {
4749
"psr-4": {
48-
"chillerlan\\LibraryTemplate\\": "src"
50+
"chillerlan\\TwoFactorQRCode\\": "src"
4951
}
5052
},
5153
"autoload-dev": {
5254
"psr-4": {
53-
"chillerlan\\LibraryTemplateTest\\": "tests"
55+
"chillerlan\\TwoFactorQRCodeTest\\": "tests"
5456
}
5557
},
5658
"scripts": {
5759
"phan": "@php vendor/bin/phan",
5860
"phpcs": "@php vendor/bin/phpcs -v",
59-
"phpstan": "@php vendor/bin/phpstan",
60-
"phpstan-baseline": "@php vendor/bin/phpstan --generate-baseline",
6161
"phpunit": "@php vendor/bin/phpunit"
6262
},
6363
"config": {

examples/example.php

Lines changed: 78 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,89 @@
22
/**
33
* example.php
44
*
5-
* @created 08.03.2024
5+
* @created 15.03.2026
66
* @author smiley <smiley@chillerlan.net>
7-
* @copyright 2024 smiley
7+
* @copyright 2026 smiley
88
* @license MIT
99
*/
1010
declare(strict_types=1);
1111

12+
use chillerlan\TwoFactorQRCode\TwoFactorQRCode;
13+
use chillerlan\TwoFactorQRCode\TwoFactorQRCodeOptions;
14+
1215
require_once __DIR__.'/../vendor/autoload.php';
1316

14-
$example = new \chillerlan\LibraryTemplate\Example;
17+
/**
18+
* invocation
19+
*/
20+
21+
// an options array, e.g. populated from framework config
22+
$options = [
23+
'secret_length' => 128,
24+
'adjacent' => 2,
25+
];
26+
27+
// invoke settings and TwoFactorQRCode instance
28+
$twoFactorQRCodeOptions = new TwoFactorQRCodeOptions($options);
29+
$twoFactorQRCode = new TwoFactorQRCode($twoFactorQRCodeOptions);
30+
31+
32+
/**
33+
* installation
34+
*/
35+
36+
// crate a secret, present it to the user as text
37+
$newSecret = $twoFactorQRCode->createSecret();
38+
39+
// also create a QR Code and present it to the user
40+
$qrcode = $twoFactorQRCode->getQRCode('label', 'issuer');
41+
42+
// generate a backup code and present it as well, save the counter value
43+
$backup = $twoFactorQRCode->createBackupCode(0);
44+
45+
// during the registration, let the user supply an OTP withthe above data abd verify it
46+
if($twoFactorQRCode->verifyOTP('069420')){
47+
// proceed with installation, save data
48+
echo 'yay!';
49+
}
50+
51+
52+
/**
53+
* normal usage, log-ins, reverification etc.
54+
*/
55+
56+
// set the secret from the user's data
57+
$twoFactorQRCode->setSecret('GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ');
58+
59+
// present the useer with a form field for the OTP and verify it
60+
if($twoFactorQRCode->verifyOTP('420069')){
61+
// redirect to wherever the user was headed
62+
}
63+
64+
65+
/**
66+
* using a backup code
67+
*/
68+
69+
// the user lost access to their authenticator, send them to a form separate from the usual OTP input
70+
// verify the given OTP against the stored counter value
71+
if($twoFactorQRCode->verifyBackupCode('694711', 0)){
72+
// after verification, create a new backup code and save the new counter value
73+
$newBackup = $twoFactorQRCode->createBackupCode(1);
74+
// present the new backup code to the user and make them triple check that they have carefully saved it,
75+
// then redirect them to wherever they were headed
76+
}
77+
78+
79+
/**
80+
* utility
81+
*/
82+
83+
// alternatively you can set the secret as raw binary, e.g. for migration
84+
$twoFactorQRCode->setRawSecret('decoded binary string');
85+
86+
// you can then retrieve the properly encoded secret
87+
$secret = $twoFactorQRCode->getSecret();
1588

16-
echo $example->hello();
89+
// you can also retrieve the raw secret
90+
$rawSecert = $twoFactorQRCode->getRawSecret();

phpstan-baseline.neon

Lines changed: 0 additions & 2 deletions
This file was deleted.

phpstan.dist.neon

Lines changed: 0 additions & 17 deletions
This file was deleted.

phpunit.xml.dist

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
<?xml version="1.0"?>
1+
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
44
bootstrap="vendor/autoload.php"
5-
cacheDirectory=".build/phpunit-cache"
5+
cacheResultFile=".build/phpunit.result.cache"
66
colors="true"
7+
verbose="true"
78
>
89
<testsuites>
9-
<testsuite name="chillerlan test suite">
10+
<testsuite name="php-authenticator test suite">
1011
<directory>tests</directory>
1112
</testsuite>
1213
</testsuites>
13-
<source>
14+
<coverage processUncoveredFiles="true">
1415
<include>
15-
<directory>src</directory>
16+
<directory suffix=".php">src</directory>
1617
</include>
17-
</source>
18-
<coverage>
1918
<report>
2019
<clover outputFile=".build/coverage/clover.xml"/>
2120
<xml outputDirectory=".build/coverage/coverage-xml"/>

src/Example.php

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)