Skip to content

Move to PHP 8.1 minimum version, add typing #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 33 commits into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
aeb4b00
first batch
NicolasCARPi Dec 7, 2022
a8c297c
second batch with QR providers
NicolasCARPi Dec 7, 2022
ac721e5
add php-cs-fixer
NicolasCARPi Dec 7, 2022
4be8355
remove php-parallel-lint: php-cs-fixer does much more
NicolasCARPi Dec 7, 2022
db0515e
fix versions in github workflow and add a lint-ci command
NicolasCARPi Dec 7, 2022
f1e73aa
fix the testsDependency folder
NicolasCARPi Dec 7, 2022
79988ef
add phpstan
NicolasCARPi Dec 7, 2022
225216a
fix php version in readme
NicolasCARPi Dec 9, 2022
887f261
add CHANGELOG.md
NicolasCARPi Dec 9, 2022
58a9628
add phpstan config file, ignore broken files because of optional lib
NicolasCARPi Dec 9, 2022
7e06716
use relative path for LICENSE link in README
NicolasCARPi Dec 9, 2022
75d8955
update the actions
NicolasCARPi Dec 9, 2022
aaf24a6
why is phpstan failing in actions?
NicolasCARPi Dec 9, 2022
25f463d
turns out I had a global gitignore with `lib`... -_-'
NicolasCARPi Dec 9, 2022
1e75674
fix action php version and handleColour function signature for bacon qr
NicolasCARPi Dec 9, 2022
041d0e3
fix bacon construct signature
NicolasCARPi Dec 9, 2022
db6256b
fix endroid handleColor
NicolasCARPi Dec 9, 2022
f8ba3b2
fix endroid qr provider handleErrorCorrectionLevel signature
NicolasCARPi Dec 9, 2022
f034bc7
use interface
NicolasCARPi Dec 9, 2022
ad89250
try adding php8.2 in test matrix
NicolasCARPi Dec 9, 2022
b52655b
add ignore env to php-cs-fixer for ci (php 8.2 issue)
NicolasCARPi Dec 9, 2022
e049285
use lint-ci for bacon test
NicolasCARPi Dec 9, 2022
4711674
crank phpstan to level 6
NicolasCARPi Dec 29, 2022
921425d
use psr12 in phpcs config
NicolasCARPi Dec 29, 2022
656e966
remove useless function comment
NicolasCARPi Dec 29, 2022
dc4e99e
use @PHP82Migration ruleset
NicolasCARPi Dec 29, 2022
86338cf
split constructor in multilines
NicolasCARPi Dec 29, 2022
a968dd3
remove the MightNotMakeAssertions shim
NicolasCARPi Dec 29, 2022
e6e5d59
lint
NicolasCARPi Dec 29, 2022
afb5cb0
add Nicolas CARPi to authors in composer.json
NicolasCARPi Feb 20, 2023
023bfc1
add Will Power in authors list in composer.json
NicolasCARPi Feb 20, 2023
ab76ac7
use phpunit 9 instead of `@stable`
NicolasCARPi Feb 20, 2023
30248a8
address remarks made by MasterOdin
NicolasCARPi Feb 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/test-bacon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:

strategy:
matrix:
php-version: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
php-version: ['8.1', '8.2']

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: shivammathur/setup-php@v2
with:
Expand All @@ -22,9 +22,9 @@ jobs:
coverage: xdebug
ini-values: error_reporting=E_ALL

- uses: ramsey/composer-install@v1
- uses: ramsey/composer-install@v2

- run: composer require bacon/bacon-qr-code

- run: composer lint
- run: composer lint-ci
- run: composer test testsDependency/BaconQRCodeTest.php
23 changes: 4 additions & 19 deletions .github/workflows/test-endroid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,11 @@ jobs:

strategy:
matrix:
php-version: ['8.0', '8.1']
php-version: ['8.1', '8.2']
endroid-version: ["^4"]
include:
- php-version: 5.6
# earliest supported version
endroid-version: 2.2.1
- php-version: 7.0
endroid-version: 2.5.1
- php-version: 7.1
# this version is 7.1+
endroid-version: 3.0.0
- php-version: 7.2
# all later versions are 7.3+
endroid-version: 3.5.9
- php-version: 7.3
endroid-version: 3.9.7
- php-version: 7.4
endroid-version: 4.0.0

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: shivammathur/setup-php@v2
with:
Expand All @@ -39,8 +23,9 @@ jobs:
coverage: xdebug
ini-values: error_reporting=E_ALL

- uses: ramsey/composer-install@v1
- uses: ramsey/composer-install@v2

- run: composer require endroid/qrcode:${{ matrix.endroid-version }}

- run: composer lint-ci
- run: composer test testsDependency/EndroidQRCodeTest.php
9 changes: 5 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:

strategy:
matrix:
php-version: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
php-version: ['8.1', '8.2']

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: shivammathur/setup-php@v2
with:
Expand All @@ -22,7 +22,8 @@ jobs:
coverage: xdebug
ini-values: error_reporting=E_ALL

- uses: ramsey/composer-install@v1
- uses: ramsey/composer-install@v2

- run: composer lint
- run: composer lint-ci
- run: composer phpstan
- run: composer test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,4 @@ composer.lock
.vs/

.phpunit.result.cache
.php-cs-fixer.cache
61 changes: 61 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php declare(strict_types=1);

/**
* PHP-CS-Fixer config for RobThree/TwoFactorAuth
*/
$finder = PhpCsFixer\Finder::create()
->name('/\.php|\.php.dist$/')
->exclude('build')
->exclude('demo')
->exclude('docs')
->in(['lib', 'tests', 'testsDependency'])
;

$config = new PhpCsFixer\Config();

return $config->setRules(array(
'@PSR2' => true,
'@PSR12' => true,
'@PHP82Migration' => true,
'array_syntax' => ['syntax' => 'long'],
'class_attributes_separation' => true,
'declare_strict_types' => true,
'dir_constant' => true,
'is_null' => true,
'no_homoglyph_names' => true,
'no_null_property_initialization' => true,
'no_php4_constructor' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'non_printable_character' => true,
'ordered_imports' => true,
'ordered_class_elements' => true,
'php_unit_construct' => true,
'pow_to_exponentiation' => true,
'psr_autoloading' => true,
'random_api_migration' => true,
'return_assignment' => true,
'self_accessor' => true,
'semicolon_after_instruction' => true,
'short_scalar_cast' => true,
'simplified_null_return' => true,
'single_blank_line_before_namespace' => true,
'single_class_element_per_statement' => true,
'single_line_comment_style' => true,
'single_quote' => true,
'space_after_semicolon' => true,
'standardize_not_equals' => true,
'strict_param' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline' => true,
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'global_namespace_import' => [
'import_classes' => true,
'import_functions' => true,
'import_constants' => true,
],
))
->setFinder($finder)
->setRiskyAllowed(true)
;
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# RobThree\TwoFactorAuth changelog

# Version 2.x

## Breaking changes

### PHP Version

Version 2.x requires at least PHP 8.1.

### Constructor signature

With version 2.x, the `algorithm` parameter of `RobThree\Auth\TwoFactorAuth` constructor is now an `enum`.

On version 1.x:

~~~php
use RobThree\Auth\TwoFactorAuth;

$lib = new TwoFactorAuth('issuer-name', 6, 30, 'sha1');
~~~

On version 2.x, simple change the algorithm from a `string` to the correct `enum`:

~~~php
use RobThree\Auth\TwoFactorAuth;
use RobThree\Auth\Algorithm;

$lib = new TwoFactorAuth('issuer-name', 6, 30, Algorithm::Sha1);
~~~

See the [Algorithm.php](./lib/Algorithm.php) file to see available algorithms.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ PHP library for [two-factor (or multi-factor) authentication](http://en.wikipedi

## Requirements

* Tested on PHP 5.6 up to 8.0
* Requires PHP version >=8.1
* [cURL](http://php.net/manual/en/book.curl.php) when using the provided `QRServerProvider` (default), `ImageChartsQRCodeProvider` or `QRicketProvider` but you can also provide your own QR-code provider.
* [random_bytes()](http://php.net/manual/en/function.random-bytes.php), [MCrypt](http://php.net/manual/en/book.mcrypt.php), [OpenSSL](http://php.net/manual/en/book.openssl.php) or [Hash](http://php.net/manual/en/book.hash.php) depending on which built-in RNG you use (TwoFactorAuth will try to 'autodetect' and use the best available); however: feel free to provide your own (CS)RNG.
* [random_bytes()](http://php.net/manual/en/function.random-bytes.php), [OpenSSL](http://php.net/manual/en/book.openssl.php) or [Hash](http://php.net/manual/en/book.hash.php) depending on which built-in RNG you use (TwoFactorAuth will try to 'autodetect' and use the best available); however: feel free to provide your own (CS)RNG.

Optionally, you may need:

Expand All @@ -38,6 +38,6 @@ If you need more in-depth information about the configuration available then you

## License

Licensed under MIT license. See [LICENSE](https://raw.githubusercontent.com/RobThree/TwoFactorAuth/master/LICENSE) for details.
Licensed under MIT license. See [LICENSE](./LICENSE) for details.

[Logo / icon](http://www.iconmay.com/Simple/Travel_and_Tourism_Part_2/luggage_lock_safety_baggage_keys_cylinder_lock_hotel_travel_tourism_luggage_lock_icon_465) under CC0 1.0 Universal (CC0 1.0) Public Domain Dedication ([Archived page](http://riii.nl/tm7ap))
5 changes: 2 additions & 3 deletions TwoFactorAuth.phpproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PHPDevHostName>localhost</PHPDevHostName>
<IISProjectUrl>http://localhost:41315/</IISProjectUrl>
<Runtime>PHP</Runtime>
<RuntimeVersion>7.0</RuntimeVersion>
<RuntimeVersion>8.1</RuntimeVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<IncludeDebugInformation>true</IncludeDebugInformation>
Expand All @@ -34,7 +34,6 @@
<Compile Include="lib\Providers\Qr\QRServerProvider.php" />
<Compile Include="lib\Providers\Rng\CSRNGProvider.php" />
<Compile Include="lib\Providers\Rng\IRNGProvider.php" />
<Compile Include="lib\Providers\Rng\MCryptRNGProvider.php" />
<Compile Include="lib\Providers\Rng\OpenSSLRNGProvider.php" />
<Compile Include="lib\Providers\Rng\HashRNGProvider.php" />
<Compile Include="lib\Providers\Rng\RNGException.php" />
Expand Down Expand Up @@ -67,4 +66,4 @@
<Content Include="LICENSE" />
<Content Include="phpunit.xml" />
</ItemGroup>
</Project>
</Project>
25 changes: 21 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,29 @@
"name": "Rob Janssen",
"homepage": "http://robiii.me",
"role": "Developer"
},
{
"name": "Nicolas CARPi",
"homepage": "https://github.com/NicolasCARPi",
"role": "Developer"
},
{
"name": "Will Power",
"homepage": "https://github.com/willpower232",
"role": "Developer"
}
],
"support": {
"issues": "https://github.com/RobThree/TwoFactorAuth/issues",
"source": "https://github.com/RobThree/TwoFactorAuth"
},
"require": {
"php": ">=5.6.0"
"php": ">=8.1.0"
},
"require-dev": {
"phpunit/phpunit": "@stable",
"php-parallel-lint/php-parallel-lint": "^1.2"
"phpunit/phpunit": "^9",
"friendsofphp/php-cs-fixer": "^3.13",
"phpstan/phpstan": "^1.9"
},
"suggest": {
"bacon/bacon-qr-code": "Needed for BaconQrCodeProvider provider",
Expand All @@ -38,8 +49,14 @@
}
},
"scripts": {
"phpstan": [
"phpstan analyze --xdebug lib tests testsDependency"
],
"lint": [
"parallel-lint --exclude vendor ."
"php-cs-fixer fix -v"
],
"lint-ci": [
"PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix -v --dry-run --stop-on-violation"
],
"test": [
"XDEBUG_MODE=coverage phpunit"
Expand Down
5 changes: 2 additions & 3 deletions docs/optional-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ Argument | Default value | Use
This library also comes with some [Random Number Generator (RNG)](https://en.wikipedia.org/wiki/Random_number_generation) providers. The RNG provider generates a number of random bytes and returns these bytes as a string. These values are then used to create the secret. By default (no RNG provider specified) TwoFactorAuth will try to determine the best available RNG provider to use in this order.

1. [CSRNGProvider](https://github.com/RobThree/TwoFactorAuth/blob/master/lib/Providers/Rng/CSRNGProvider.php) for PHP7+
2. [MCryptRNGProvider](https://github.com/RobThree/TwoFactorAuth/blob/master/lib/Providers/Rng/MCryptRNGProvider.php) where mcrypt is available
3. [OpenSSLRNGProvider](https://github.com/RobThree/TwoFactorAuth/blob/master/lib/Providers/Rng/OpenSSLRNGProvider.php) where openssl is available
4. [HashRNGProvider](https://github.com/RobThree/TwoFactorAuth/blob/master/lib/Providers/Rng/HashRNGProvider.php) **non-cryptographically secure** fallback
2. [OpenSSLRNGProvider](https://github.com/RobThree/TwoFactorAuth/blob/master/lib/Providers/Rng/OpenSSLRNGProvider.php) where openssl is available
3. [HashRNGProvider](https://github.com/RobThree/TwoFactorAuth/blob/master/lib/Providers/Rng/HashRNGProvider.php) **non-cryptographically secure** fallback

Each of these RNG providers have some constructor arguments that allow you to tweak some of the settings to use when creating the random bytes.

Expand Down
16 changes: 16 additions & 0 deletions lib/Algorithm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace RobThree\Auth;

/**
* List of supported cryptographic algorithms
*/
enum Algorithm: string
{
case Md5 = 'md5';
case Sha1 = 'sha1';
case Sha256 = 'sha256';
case Sha512 = 'sha512';
}
Loading