Giter Site home page Giter Site logo

antonioribeiro / google2fa Goto Github PK

View Code? Open in Web Editor NEW
1.8K 50.0 193.0 482 KB

A One Time Password Authentication package, compatible with Google Authenticator.

License: MIT License

PHP 96.99% Shell 3.01%
php 2fa two-factor-authentication google2fa agnostic hacktoberfest

google2fa's Introduction

Google2FA

Google Two-Factor Authentication for PHP

Google2FA is a PHP implementation of the Google Two-Factor Authentication Module, supporting the HMAC-Based One-time Password (HOTP) algorithm specified in RFC 4226 and the Time-based One-time Password (TOTP) algorithm specified in RFC 6238.


Latest Stable Version License Code Quality Build Downloads

Monthly Downloads Coverage PHP


Menu

Version Compatibility

PHP Google2FA
5.4 7.x LTS
5.5 7.x LTS
5.6 7.x LTS
7.1 8.x
7.2 8.x
7.3 8.x
7.4 8.x
8.0 (β) 8.x

Laravel bridge

This package is agnostic, but there's a Laravel bridge.

About QRCode generation

This package does not generate QRCodes for 2FA.

If you are looking for Google Two-Factor Authentication, but also need to generate QRCode for it, you can use the Google2FA QRCode package, which integrates this package and also generates QRCodes using the BaconQRCode library, or check options on how to do it yourself here in the docs.

Demos, Example & Playground

Please check the Google2FA Package Playground.

playground

Here's a demo app showing how to use Google2FA: google2fa-example.

You can scan the QR code on this (old) demo page with a Google Authenticator app and view the code changing (almost) in real time.

Requirements

  • PHP 7.1 or greater

Installing

Use Composer to install it:

composer require pragmarx/google2fa

To generate inline QRCodes, you'll need to install a QR code generator, e.g. BaconQrCode:

composer require bacon/bacon-qr-code

Usage

Instantiate it directly

use PragmaRX\Google2FA\Google2FA;
    
$google2fa = new Google2FA();
    
return $google2fa->generateSecretKey();

How To Generate And Use Two Factor Authentication

Generate a secret key for your user and save it:

$user->google2fa_secret = $google2fa->generateSecretKey();

Generating QRCodes

The more secure way of creating QRCode is to do it yourself or using a library. First you have to install a QR code generator e.g. BaconQrCode, as stated above, then you just have to generate the QR code url using:

$qrCodeUrl = $google2fa->getQRCodeUrl(
    $companyName,
    $companyEmail,
    $secretKey
);

Once you have the QR code url, you can feed it to your preferred QR code generator.

// Use your own QR Code generator to generate a data URL:
$google2fa_url = custom_generate_qrcode_url($qrCodeUrl);

/// and in your view:

<img src="{{ $google2fa_url }}" alt="">

And to verify, you just have to:

$secret = $request->input('secret');

$valid = $google2fa->verifyKey($user->google2fa_secret, $secret);

QR Code Packages

This package suggests the use of Bacon/QRCode because it is known as a good QR Code package, but you can use it with any other package, for instance Google2FA QRCode, Simple QrCode or Endroid QR Code, all of them use Bacon/QRCode to produce QR Codes.

Usually you'll need a 2FA URL, so you just have to use the URL generator:

$google2fa->getQRCodeUrl($companyName, $companyEmail, $secretKey)

Examples of Usage

Get a QRCode to be used inline:

$google2fa = (new \PragmaRX\Google2FAQRCode\Google2FA());

$inlineUrl = $google2fa->getQRCodeInline(
    'Company Name',
    '[email protected]',
    $google2fa->generateSecretKey()
);

And use in your template:

<img src="{{ $inlineUrl }}">
<div class="visible-print text-center">
    {!! QrCode::size(100)->generate($google2fa->getQRCodeUrl($companyName, $companyEmail, $secretKey)); !!}
    <p>Scan me to return to the original page.</p>
</div>

Generate the data URL

$qrCode = new \Endroid\QrCode\QrCode($value);
$qrCode->setSize(100);
$google2fa_url = $qrCode->writeDataUri();

And in your view

<div class="visible-print text-center">
    {!! $google2fa_url !!}
    <p>Scan me to return to the original page.</p>
</div>
<?php

use PragmaRX\Google2FA\Google2FA;
use BaconQrCode\Renderer\ImageRenderer;
use BaconQrCode\Renderer\Image\ImagickImageBackEnd;
use BaconQrCode\Renderer\RendererStyle\RendererStyle;
use BaconQrCode\Writer;

$google2fa = app(Google2FA::class);

$g2faUrl = $google2fa->getQRCodeUrl(
    'pragmarx',
    '[email protected]',
    $google2fa->generateSecretKey()
);

$writer = new Writer(
    new ImageRenderer(
        new RendererStyle(400),
        new ImagickImageBackEnd()
    )
);

$qrcode_image = base64_encode($writer->writeString($g2faUrl));

And show it as an image:

<img src="data:image/png;base64, <?php echo $qrcode_image; ?> "/>

HMAC Algorithms

To comply with RFC6238, this package supports SHA1, SHA256 and SHA512. It defaults to SHA1, so to use a different algorithm you just have to use the method setAlgorith():

use PragmaRX\Google2FA\Support\Constants;

$google2fa->setAlgorithm(Constants::SHA512);

Server Time

It's really important that you keep your server time in sync with some NTP server, on Ubuntu you can add this to the crontab:

sudo service ntp stop
sudo ntpd -gq
sudo service ntp start

Validation Window

To avoid problems with clocks that are slightly out of sync, we do not check against the current key only but also consider $window keys each from the past and future. You can pass $window as optional third parameter to verifyKey, it defaults to 4. A new key is generated every 30 seconds, so this window includes keys from the previous two and next two minutes.

$secret = $request->input('secret');

$window = 8; // 8 keys (respectively 4 minutes) past and future

$valid = $google2fa->verifyKey($user->google2fa_secret, $secret, $window);

An attacker might be able to watch the user entering his credentials and one time key. Without further precautions, the key remains valid until it is no longer within the window of the server time. In order to prevent usage of a one time key that has already been used, you can utilize the verifyKeyNewer function.

$secret = $request->input('secret');

$timestamp = $google2fa->verifyKeyNewer($user->google2fa_secret, $secret, $user->google2fa_ts);

if ($timestamp !== false) {
    $user->update(['google2fa_ts' => $timestamp]);
    // successful
} else {
    // failed
}

Note that $timestamp is either false (if the key is invalid or has been used before) or the provided key's unix timestamp divided by the key regeneration period of 30 seconds.

Using a Bigger and Prefixing the Secret Key

Although the probability of collision of a 16 bytes (128 bits) random string is very low, you can harden it by:

Use a bigger key

$secretKey = $google2fa->generateSecretKey(32); // defaults to 16 bytes

You can prefix your secret keys

You may prefix your secret keys, but you have to understand that, as your secret key must have length in power of 2, your prefix will have to have a complementary size. So if your key is 16 bytes long, if you add a prefix it must also be 16 bytes long, but as your prefixes will be converted to base 32, the max length of your prefix is 10 bytes. So, those are the sizes you can use in your prefixes:

1, 2, 5, 10, 20, 40, 80...

And it can be used like so:

$prefix = strpad($userId, 10, 'X');

$secretKey = $google2fa->generateSecretKey(16, $prefix);

Window

The Window property defines how long a OTP will work, or how many cycles it will last. A key has a 30 seconds cycle, setting the window to 0 will make the key last for those 30 seconds, setting it to 2 will make it last for 120 seconds. This is how you set the window:

$secretKey = $google2fa->setWindow(4);

But you can also set the window while checking the key. If you need to set a window of 4 during key verification, this is how you do:

$isValid = $google2fa->verifyKey($seed, $key, 4);

Key Regeneration Interval

You can change key regeneration interval, which defaults to 30 seconds, but remember that this is a default value on most authentication apps, like Google Authenticator, which will, basically, make your app out of sync with them.

$google2fa->setKeyRegeneration(40);

Google Authenticator secret key compatibility

To be compatible with Google Authenticator, your (converted to base 32) secret key length must be at least 8 chars and be a power of 2: 8, 16, 32, 64...

So, to prevent errors, you can do something like this while generating it:

$secretKey = '123456789';
  
$secretKey = str_pad($secretKey, pow(2,ceil(log(strlen($secretKey),2))), 'X');

And it will generate

123456789XXXXXXX

By default, this package will enforce compatibility, but, if Google Authenticator is not a target, you can disable it by doing

$google2fa->setEnforceGoogleAuthenticatorCompatibility(false);

Google Authenticator Apps

To use the two factor authentication, your user will have to install a Google Authenticator compatible app, those are some of the currently available:

Deprecation Warning

Google API for QR generator is turned off. All versions of that package prior to 5.0.0 are deprecated. Please upgrade and check documentation regarding QRCode generation.

Testing

The package tests were written with PHPUnit. There are some Composer scripts to help you run tests and analysis:

PHPUnit:

composer test

PHPStan analysis:

composer analyse

Authors

License

Google2FA is licensed under the MIT License - see the LICENSE file for details.

Contributing

Pull requests and issues are more than welcome.

Sponsorships

Direct

None.

Indirect

google2fa's People

Contributors

acgtwentyone avatar antonioribeiro avatar barryvdh avatar choonge avatar cnanney avatar daveismynamecom avatar domodwyer avatar drbyte avatar grahamcampbell avatar it-can avatar jbrooksuk avatar kartavik avatar krsriq avatar leandro-lugaresi avatar mfn avatar mikerockett avatar naneri avatar ngyikp avatar paolaruby avatar pixellup avatar proshanto avatar sebastians90 avatar snipe avatar spaze avatar stylecibot avatar taichunmin avatar tshafer avatar victormac3000 avatar wells avatar zhiyi7 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

google2fa's Issues

DB fields / middleware

Is the "google2fa_secret" attribute the only one, I need to add to my user model?
-Regarding the middleware, is there some included already? I already read about middleware in the issue section.

feature request: using qrcodejs to remove dependency simplesoftwareio/simple-qrcode

feature request: using qrcodejs to remove dependency simplesoftwareio/simple-qrcode

show QRCode is a front-end need, so it is reasonable to achieve it in Client Side with javascript.
qrcodejs is a perfect solution for this.
(leave the show QRCode task to the front-end guy 🎃 )
ext-gd and simplesoftwareio/simple-qrcode are heavy dependency for 2fa server side package

Relicensing to MIT

Dear contributors,

To allow this package to be adopted by other projects, I'm trying to move the license of this package from the original GPLv3 to something more permissive, like MIT, but I need you and the original developer (Phil), to approve it.

So, I'm listing all of you (up to today) and ask for a YAY/NAY comment in this thread, from each one of you.

If you have any questions or something to say about this change, please do.

If you have a really good understanding of licensing (which I do not), please jump in and help us.

Unique secret key

It is a good practice to check if a generated secret key is unique in the User DB table, that is not yet assigned to another user (statistically is improbable, but not sure).

Won't install. Problem with paragonie/random_compat

Software versions

PHP 7.2.8 (cli) (built: Jul 19 2018 12:15:24) ( NTS )
Composer version 1.7.2 2018-08-16 16:57:12

After composer require
get this

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Conclusion: don't install pragmarx/google2fa v3.0.2
    - Conclusion: don't install pragmarx/google2fa v3.0.1
    - Conclusion: remove paragonie/random_compat v9.99.99
    - Installation request for pragmarx/google2fa ^3.0 -> satisfiable by pragmarx/google2fa[v3.0.0, v3.0.1, v3.0.2].
    - Conclusion: don't install paragonie/random_compat v9.99.99
    - pragmarx/google2fa v3.0.0 requires paragonie/random_compat ~1.4|~2.0 -> satisfiable by paragonie/random_compat[v1.4.0, v1.4.1, v1.4.2, v1.4.3, v2.0.0, v2.0.1, v2.0.10, v2.0.11, v2.0.12, v2.0.13, v2.0.14, v2.0.15, v2.0.16, v2.0.17, v2.0.2, v2.0.3, v2.0.4, v2.0.5, v2.0.6, v2.0.7, v2.0.8, v2.0.9].
    - Can only install one of: paragonie/random_compat[v1.4.0, v9.99.99].
    - Can only install one of: paragonie/random_compat[v1.4.1, v9.99.99].
    - Can only install one of: paragonie/random_compat[v1.4.2, v9.99.99].
    - Can only install one of: paragonie/random_compat[v1.4.3, v9.99.99].
    - Can only install one of: paragonie/random_compat[v2.0.0, v9.99.99].
    - Can only install one of: paragonie/random_compat[v2.0.1, v9.99.99].
    - Can only install one of: paragonie/random_compat[v2.0.10, v9.99.99].
    - Can only install one of: paragonie/random_compat[v2.0.11, v9.99.99].
    - Can only install one of: paragonie/random_compat[v2.0.12, v9.99.99].
    - Can only install one of: paragonie/random_compat[v2.0.13, v9.99.99].
    - Can only install one of: paragonie/random_compat[v2.0.14, v9.99.99].
    - Can only install one of: paragonie/random_compat[v2.0.15, v9.99.99].
    - Can only install one of: paragonie/random_compat[v2.0.16, v9.99.99].
    - Can only install one of: paragonie/random_compat[v2.0.17, v9.99.99].
    - Can only install one of: paragonie/random_compat[v2.0.2, v9.99.99].
    - Can only install one of: paragonie/random_compat[v2.0.3, v9.99.99].
    - Can only install one of: paragonie/random_compat[v2.0.4, v9.99.99].
    - Can only install one of: paragonie/random_compat[v2.0.5, v9.99.99].
    - Can only install one of: paragonie/random_compat[v2.0.6, v9.99.99].
    - Can only install one of: paragonie/random_compat[v2.0.7, v9.99.99].
    - Can only install one of: paragonie/random_compat[v2.0.8, v9.99.99].
    - Can only install one of: paragonie/random_compat[v2.0.9, v9.99.99].
    - Installation request for paragonie/random_compat (locked at v9.99.99) -> satisfiable by paragonie/random_compat[v9.99.99].

verifyKeyNewer checks "newer or equal" instead of "strictly newer"

First of all, thank you so much for merging and improving my PR (#50)!

But are you sure that this change in the specification is correct?

 public function it_verifies_keys_newer()
 {
   $this->verifyKeyNewer($this->secret, '512396', 26213401, 2, 26213400)->shouldBe(false);    // 26213400
-  $this->verifyKeyNewer($this->secret, '410272', 26213401, 2, 26213400)->shouldBe(false);    // 26213401
+  $this->verifyKeyNewer($this->secret, '410272', 26213401, 2, 26213400)->shouldBe(26213401);    // 26213401
   $this->verifyKeyNewer($this->secret, '239815', 26213401, 2, 26213400)->shouldBe(26213402); // 26213402
   $this->verifyKeyNewer($this->secret, '313366', 26213401, 2, 26213400)->shouldBe(false);    // 26213403
 }

For me it looks wrong, especially when looking at the example from the readme file:

$secret = $request->input('secret');

$timestamp = $google2fa->verifyKeyNewer($user->google2fa_secret, $secret, $user->google2fa_ts);

if ($timestamp !== false) {
    $user->update(['google2fa_ts' => $timestamp]);
    // successful
} else {
    // failed
}

There we store the returned timestamp into the user model, and take it from there for the next verifyKeyNewer call. The comparison therefore must be "strictly newer" and not "newer or equal".
With your change, the situation is as follows (assuming that timestamp 26213401 is in the window):

  • The user provides the token 410272 which is for the timestamp 26213401. Assume that this timestamp is new, i.e. the check will pass.
  • The verifyKeyNewer call returns 26213401, we store that timestamp into the user model.
  • An attacker has witnessed the user entering credentials and otp token. He therefore knows the token. While still being in the window, he tries to login with correct credentials and the same token 410272.
  • We check: $google2fa->verifyKeyNewer($user->google2fa_secret, 410272, 26213401), which returns 26213401 as specified by your changed test.
  • The attacker therefore can login, reusing the already used token.

To resolve this, we either can:

  • change the test to ->shouldBe(false) again and make sure that the implementation passes this test, or
  • change the readme and instruct to increment the timestamp at some point, e.g.
    $user->update(['google2fa_ts' => $timestamp + 1]); (but this sounds less convenient)

I might be wrong, as I haven't yet found the time to thoroughly test your new version, but the changed test feels wrong for me.

Anyways, thanks a lot for the effort you put into maintaining this package and further improving it for Laravel 5.5.

Problems on production

I've been using this package in many projects now, and it's really strange that in the current one I'm on, when I push to production, the tokens are invalidated, though the secret and token are being sent properly.

Is there any known "tip" or something we should know of?

Thanks!

verifyKeyNewer Not working Correctly

I have a new user which does not have an old timestamp, so when validation happens it returns true, should it not return the timestamp instead?

Here is what im doing :


        $valid = $this->google2FA->verifyKeyNewer(
            $request->user()->second_auth_secret,
            $request->get('token'),
            $request->user()->second_auth_updated_at ? $request->user()->second_auth_updated_at->timestamp : null
        );

// since valid is a true / false 
        if ($valid !== false) {

            $request->user()->update([
                'second_auth_active' => true,
                // this is a true or false currently 
                'second_auth_updated_at' =>$valid,
            ]);
        }

[Q] keyRegeneration period and window (key)

Hi there! Yesterday I played a bit with G2FA and now have a question. (I don't know another place to ask and I know that the original code was made by a Phil …)

Background of my understanding

G2FA generates (default) every 30 secs (= keyRegeneration) a new OTP with a valid. time/period from now (= timeStamp) up to now + 4x30 secs (now is rounded down to the last 30st second).

Example one

now: 11:03:54
valid from: 11:03:30
valid up to: 11:05:30

Example two

now: 11:03:15
valid from: 11:03:00
valid up to: 11:05:00

Questions

Examples

With the above examples my expected valid up to-time is not true. My OTPs always are 30 secs longer valid.

example one = up to 11:06:00
example two = up to 11:05:30

→ So I'm missing something or is my understanding wrong?

My scenario

Is a scenario where OTPs are generated every second and are valid for 20 secs realisable/feasible. And if yes, how can I do it?

Tanks a lot for your help and best regards!

Recovery Codes Question

Thanks for the awesome work on this! I've implemented this package into Laravel and it works great!

I'm now trying to generate recover codes or back up codes. Like this page: https://support.google.com/accounts/answer/1187538?hl=en
How are you generating recovery codes (backup codes) incase a user doesn't have their phone?

I've looked through the code and have been thinking of different ways I can implement a recovery code list, but coming up empty handed.

Can the one time password method oathHotp be used in a loop to generate those codes?

random_int only php7

you mention it is compatible with php 5.4 but the function random_int in base32 trait is only available in php7 and will return an error message

Backup Code

Have an way to create a Backup list of codes, like if my user don't have the cellphone next, he/her can use one code of the list.

Security Alert: Susceptible to MITM Attacks

In the documentation it suggests using:

$google2fa_url = Google2FA::getQRCodeGoogleUrl(
    'YourCompany',
    $user->email,
    $user->google2fa_secret
);

This generates a URL to Google Charts.
Using this URL creates a GET request which allows all of the information to sniffed.

Using:

$google2fa_url = Google2FA::getQRCodeGoogleUrl(
    'YourCompany',
    'email',
    'OhHeyThe2faSecret'
);

Returns: https://chart.googleapis.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth%3A%2F%2Ftotp%2FYourCompany%3Aemail%3Fsecret%3DOhHeyThe2faSecret%26issuer%3DYourCompany
If you decode the &chl= part you get: otpauth://totp/YourCompany:email?secret=OhHeyThe2faSecret&issuer=YourCompany

The QR code should be generated server side rather than being passed to a 3rd Party.

Adding any prefix generates an unusable secret

When I tried using no prefix:
$otp_secret = $google2fa->generateSecretKey(16);
It generates a usable secret, tested by Authy on iOS (manually key in the secret, or QR code scan)

When I tried using a blank prefix:
$otp_secret = $google2fa->generateSecretKey(16, '');
It generates a usable secret, tested by Authy on iOS (manually key in the secret, or QR code scan)

When I add a prefix prefix:
$otp_secret = $google2fa->generateSecretKey(16, 'm');
$otp_secret = $google2fa->generateSecretKey(16, 'mel');
$otp_secret = $google2fa->generateSecretKey(16, 'melvin');
All 3 lines yield an error, whether manually keying in the secret, or QR code scan.

Anybody else encounter this problem?

Using a space results in an invalid barcode

If you use a company new with a space it wil result in an invalid barcode.

$google2fa_url = Google2FA::getQRCodeGoogleUrl(
    'My Company',
    $user->email,
    $user->google2fa_secret
);

README Typo

There's a small error, where you register the facade, it points to ServiceProvider instead of Facade, so instead of:

'Google2FA' => 'PragmaRX\Google2FA\Vendor\Laravel\ServiceProvider',

It should be

'Google2FA' => 'PragmaRX\Google2FA\Vendor\Laravel\Facade',

Great package by the way, thanks.

Not found class PragmaRX\Google2FA\Google2FA

use PragmaRX\Google2FA\Google2FA;

        $gFA = new Google2FA();

        $imageDataUri = $gFA->getQRCodeInline(
            $request->getHttpHost(),
            $user->email,
            $secret,
            200
        );

Class 'PragmaRX\Google2FA\Google2FA' not found
How to fix for Laravel 5.3 ?

Uncaught Error: Call to a member function input() on null in

I have sort of the same problem as what JordyKroeze had. Even if I have entered the TOTP from Authenticator Plus after I scanned the QR code, it only generate Uncaught Error: Call to a member function input() on null in .... Why?

Here's is my current code:

use PragmaRX\Google2FA\Google2FA;

$google2fa = new Google2FA();
$tfa_secretkey = $google2fa->generateSecretKey();
$input = $_POST['textfield-verify-code'];    # This is the input that the user enters theirs TOTP
$secret = $request->input($input);
$window = 8;
$valid = $google2fa->verifyKey($tfa_secretkey, $secret, $window);

echo $valid;

verifyKey returning false everytime.

This is my code, i am unable to figure out why $vaild is returning false every time.

<?php

$user = array('email' =>'[email protected]','google2fa_secret'=>$google2fa->generateSecretKey(16));

$google2fa->setAllowInsecureCallToGoogleApis(true);

$google2fa_url = $google2fa->getQRCodeGoogleUrl(
    'Redipay.com',
    $user['email'],
    $user['google2fa_secret']
);

//print_r($user);
/// and in your view:

echo '<img src="'.$google2fa_url.'" alt="">';


//print_r($_POST);
if($_POST['Verify']){

echo 'secret Submitted by you' . $_POST['secret'];

$secret = $_POST['secret'];

$valid = $google2fa->verifyKey($user['google2fa_secret'], $secret, 8);

if($valid){
	
	echo 'code is valid';

}else{
	echo "Please provide Correct information.";
}

}


?>


<form action="" method="POST" >
	<input type="text" name="secret" class="form-control col-sm-6" placeholder="enter your secret code" />
	<button type="submit" name="Verify" value="Verify">Verify</button>
</form>

QR Codes not working in Laravel 5.4.

I keep getting invalid QR codes when using default settings on Laravel 5.4.
Here is my code:

/**
     * Generate a new 2FA key.
     *
     * @return void
     */
    public function setup2FA(Google2FA $google2fa)
    {
        $user = Auth::user();
        $google2fa_secret = $google2fa->generateSecretKey();
        $google2fa_url = $google2fa->getQRCodeGoogleUrl(
            config('app.name', 'Laravel'),
            $user->email,
            $user->google2fa_secret
        );

        return view('2fa.setup', ['google2fa_secret' => $google2fa_secret, 'google2fa_url' => $google2fa_url]);
    }

I should note that I am using the Microsoft Authenticator app on Windows 10 mobile, but my coworker is having the same issue using Google Authenticator on Android.
Also the Secrets themselves work just fine, if entered manually.
What gives?

License?

You say at the bottom that the license is BSD-3, but the badge at the top of the README file says MIT. Guessing the MIT one is wrong at the top?

$secret = $request->input('secret'); not found

Hello,

When i follow the readme i get a QRcode and everyting.

But i get this error if i try to check the code.

Notice: Undefined variable: request in FILENAME on line 30

Fatal error: Call to a member function input() on a non-object in FILENAME on line 30

Line 30 is this (Changed my secretkey)
$secret = $request->input('abcdef');

Where is this request variable coming from ?

License inconsistency

While composer.json states "BSD-3-Clause" (as the LICENSE file), the file header states "GPLv3+"

Can you please clarify ?

Return type of getTimestamp()

The return type of getTimestamp is specified to be int.
But the value returned is the result from floor, and that is float (see documentation).

You even test that the value is a float.

Can we make that consistent, please?

  • Return int
    • Insert a cast to int in getTimestamp
    • Adjust the test to check is_int
  • Return float
    • Fix @return annotation in interface and class

I can do a pull request for either choice if you tell me which way to go. In my opinion, int is better here because the value is floored anyways and even a 32 bit signed integer for a unix timestamp divided by 30 will be enough for almost another 2000 years - and by that time everyone should have switched to a system aware of 64 bit integers 😄

Default value for parameters with a class type hint can only be NULL

Laravel 5.4 Php 5.6

$user = User::first();
$google2fa = new Google2FA();
$code_from_app = "332117";

$valid = $google2fa->verifyKey($user->google2fa_secret, $code_from_app);

Throwing error : Default value for parameters with a class type hint can only be NULL

selection_080

I had some search and found that php-cs-fixer issue it requires PHP 7.1 but i haven't used that and for this library min PHP version require is 5.4 So, please look into this issue.

Thanks

Class does not exist

I'm getting this error with either 5.4 or 5.5 Laravel versions:

"Class pragmarx.google2fa does not exist"

Already tried composer update... Any ideia?

Old tokens are valid

Verifying old tokens which has been used minutes ago get validated. Is there some way to disable old keys?

External Service for QR-Code that includes the secret code

Hello,

regarding QRCode::getQRCodeGoogleUrl. I don't think it is a good idea to use an external service for showing the qr code containing the secret key. Shouldn't this secret key be only in the hands of the one to be authenticated? If you use this method, also an external service gets this secret information.

A major security flaw imho.

Kind Regards

Middleware for L5

If this package had middleware you could require 2fa for certain routes (like /admin & /settings) or all routes.

It would redirect to a screen to enter that info then redirect back to the intended resource just like login.

Generated secret key isn't cryptographically secure

The Google2FA::generateSecretKey method internally uses Google2FA::getRandomNumber, which uses mt_rand function. According to its documentation (see http://php.net/mt_rand) it should not be used in security-related contexts.

Since current usage exactly qualifies as security related context I'm proposing to:

  1. use https://packagist.org/packages/paragonie/random_compat package to get random_int function, that was added only in PHP 7
  2. use random_int instead of mt_rand

If you're interested I can send a PR.

problem with KEY_REGENERATION

i change value from 30second such as 25,45 to reduce lifetime of generate code but it not work

help me please i am newbie for google2FA

Class 'PragmaRX\Google2FA\Vendor\Laravel\ServiceProvider' not found

I am experiencing an issue in Laravel 5.2 after registering this class.

I installed the package with composer, registered it in app.php. I also did a composer dumpautoload and cleared the cache with artisan, but I still get this error each time. I can see the files exist in vendor and all looks good there. I have also manually deleted the cache thinking that could have been the issue but no luck so far.

`# php artisan config:cache

[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'PragmaRX\Google2FA\Vendor\Laravel\ServiceProvider' not found`

0.6.0 Release

Is this release planned. Anything I can help with?

Trait 'Illuminate\Foundation\Events\Dispatchable' not found

The events files on google2fa-laravel/src/events not work for me on laravel 5.2.45, then i upgrade to 5.3 and still not work, i try to delete the Dispatchable and everything works fine, but i dont know how this affect other things... The event request example working for me are this

user = $user; } }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.