Skip to content
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

chore: PHP 7.2 GitHub workflows #44

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
62 changes: 62 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: CI

on: [push, pull_request]

jobs:
php-cs-fixer:
name: PHP-CS-Fixer
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: PHP-CS-Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --diff --dry-run

phpstan:
name: 'PHPStan'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Composer
uses: php-actions/composer@v5
with:
php_version: 8.0
composer_version: 2
- name: PHPStan
uses: php-actions/phpstan@v2
with:
php_version: 8.0

phpunit:
name: 'PHPUnit'
runs-on: ubuntu-latest
strategy:
# Making sure all versions get tested even if one fails
fail-fast: false
matrix:
phpunit-version:
- '9.5.0'
php-version:
- '7.3'
- '7.4'
- '8.0'
include:
- phpunit-version: '8.5.13'
php-version: '7.2'

steps:
- uses: actions/checkout@v2
- name: Composer
uses: php-actions/composer@v5
with:
php_version: ${{ matrix.php-version }}

- name: PHPUnit Tests
uses: php-actions/phpunit@v2
with:
version: ${{ matrix.phpunit-version }}
php_version: ${{ matrix.php-version }}
#bootstrap: vendor/autoload.php
#configuration: test/phpunit.xml
#args: --coverage-text
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@
/.settings
/composer.lock
/vendor/
/.idea
/.idea
.php-cs-fixer.cache
.phpunit.result.cache
build
29 changes: 29 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

$config = new PhpCsFixer\Config();
return $config
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'@PSR1' => true,
'concat_space' => true,
'declare_strict_types' => true,
'logical_operators' => true,
'native_function_casing' => true,
'native_function_invocation' => true,
'native_function_type_declaration_casing' => true,
'no_alternative_syntax' => true,
'no_leading_namespace_whitespace' => true,
'no_superfluous_phpdoc_tags' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_unused_imports' => true,
'no_whitespace_before_comma_in_array' => true,
'yoda_style' => true,
])
->setFinder(PhpCsFixer\Finder::create()
->exclude('vendor')
->in(__DIR__)
)
;
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
}
],
"require": {
"php": ">=5.6.0",
"php": "^7.2 || ^8.0",
"paragonie/constant_time_encoding": "^1|^2",
"paragonie/random_compat": ">=1",
"symfony/polyfill-php56": "^1"
},
"require-dev": {
"phpunit/phpunit": "^5.7.11 || ^6.0.5"
"friendsofphp/php-cs-fixer": "^3.51",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^8 || ^9.6"
},
"autoload": {
"psr-4": {
Expand Down
50 changes: 25 additions & 25 deletions example/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

session_start(); // using it as storage temporary

require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__.'/../vendor/autoload.php';

use Otp\Otp;
use Otp\GoogleAuthenticator;
Expand All @@ -13,12 +13,12 @@
$secret = 0;

if (isset($_SESSION['otpsecret'])) {
$secret = $_SESSION['otpsecret'];
$secret = $_SESSION['otpsecret'];
}

if (strlen($secret) != 16) {
$secret = GoogleAuthenticator::generateRandom();
$_SESSION['otpsecret'] = $secret;
if (16 != \strlen($secret)) {
$secret = GoogleAuthenticator::generateRandom();
$_SESSION['otpsecret'] = $secret;
}

// The secret is now an easy stored Base32 string.
Expand Down Expand Up @@ -72,26 +72,26 @@
<?php

if (isset($_POST['otpkey'])) {
// Sanitizing, this should take care of it
$key = preg_replace('/[^0-9]/', '', $_POST['otpkey']);
// Standard is 6 for keys, but can be changed with setDigits on $otp
if (strlen($key) == 6) {
// Remember that the secret is a base32 string that needs decoding
// to use it here!
if ($otp->checkTotp(Encoding::base32DecodeUpper($secret), $key)) {
echo 'Key correct!';
// Add here something that makes note of this key and will not allow
// the use of it, for this user for the next 2 minutes. This way you
// prevent a replay attack. Otherwise your OTP is missing one of the
// key features it can bring in security to your application!
} else {
echo 'Wrong key!';
}
} else {
echo 'Key not the correct size';
}
// Sanitizing, this should take care of it
$key = preg_replace('/[^0-9]/', '', $_POST['otpkey']);
// Standard is 6 for keys, but can be changed with setDigits on $otp
if (6 == \strlen($key)) {
// Remember that the secret is a base32 string that needs decoding
// to use it here!
if ($otp->checkTotp(Encoding::base32DecodeUpper($secret), $key)) {
echo 'Key correct!';
// Add here something that makes note of this key and will not allow
// the use of it, for this user for the next 2 minutes. This way you
// prevent a replay attack. Otherwise your OTP is missing one of the
// key features it can bring in security to your application!
} else {
echo 'Wrong key!';
}
} else {
echo 'Key not the correct size';
}
}

?>
Expand Down
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: 8
paths:
- src
- tests
15 changes: 0 additions & 15 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,12 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
colors="true">
<testsuites>
<testsuite name="Otp Test Suite">
<directory suffix="Test.php">tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>

<logging>
<log type="coverage-html" target="build/coverage" title="Otp"
charset="UTF-8" yui="true" highlight="true"
lowUpperBound="35" highLowerBound="70"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false"/>
</logging>
</phpunit>

Loading