Coder Social home page Coder Social logo

googleauthenticator.php's Introduction

Ported from http://code.google.com/p/google-authenticator/

You can use the Google Authenticator app from here
http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=1066447
to generate One Time Passwords/Tokens and check them with this little
PHP app (Of course, you can also create them with this).

There are many real world applications for that, but noone implemented it yet.

See example.php for how to use it.

There's a little web app showing how it works in web/, please make users.dat 
writeable for the webserver, doesn't really work otherwise (it can't save the
secret). Try to login with chregu/foobar.


What's missing in the example:
***

* Prevent replay attacks. One token should only be used once 
* Show QR Code only when providing password again (or not at all)
* Regenrate secret

googleauthenticator.php's People

Contributors

chregu avatar jemixs avatar jhitesma 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

googleauthenticator.php's Issues

Timezone difference

I have used this code in 2 different site which sits in 2 different server with a time difference of 1 hr and the code generated in my mobila app matches with one server (both are in same timezone) and 2nd one site doesnt match the code at all but matches after an hour. (Note i have generated 2 different secret keys and mobile app has 2 different accounts respectively).

How to work this out?

Fixed some issue with the QR URL .....

Issues Addressed:

  1. Added Issuer parameter to match the spec, separate from user
  2. Proper encoding to handle spaces in Issuer name
  3. made width and height optional parameters

Note: this may not be backward compatible given the way $domain was specified, but it does follow the Google spec located here........

https://github.com/google/google-authenticator/wiki/Key-Uri-Format

public function getUrl($issuer, $user, $secret, $width = 200, $height = 200) {
    $url =  sprintf("otpauth://totp/%s:%s?secret=%s&issuer=%s", rawurlencode($issuer), $user, $secret, rawurlencode($issuer));
    $encoder = sprintf("https://www.google.com/chart?chs=%dx%d&chld=M|0&cht=qr&chl=",$width,$height);
    $encoderURL = sprintf( "%s%s",$encoder, rawurlencode($url));

    return $encoderURL;

}

Sync with GA app at the mobile timing and script

Hello.

How I can sync GA app timing at the mobile with PHP script?

In the example I see:

$secret = 'XVQ2UIGO75XRUKJO';
$time = floor(time() / 30);
$code = "846474";

But in the GA app another timing ... And when I put code from GA app its valid. But when time is over in the GA app code still valid.

Thanks.

QR code broken - getURL() function fix within

It looks like both the QR code URL and some formatting changes are needed to get this to work correctly. Working function as of November 29, 2012:

public function getUrl($user, $hostname, $secret) {
        $url =  sprintf("otpauth://totp/%s@%s?secret=%s", $user, $hostname, $secret);
        $encoder = "https://chart.googleapis.com/chart?chs=200x200&chld=M|0&cht=qr&chl=";
        $encoderURL = $encoder . urlencode( sprintf( "otpauth://totp/%s@%s?secret=%s", $user, $hostname, $secret) );
        
        return $encoderURL;
        
    }

Allow passing 0 as $time in getCode()

Allow passing 0 in the $time argument of getCode() method.

Currently it uses a !$time condition but it should be $time === null. 0 is a perfectly valid timestamp/counter value.

Critical vulnerability with use of timing-sensitive comparison!

https://github.com/chregu/GoogleAuthenticator.php/blob/master/lib/GoogleAuthenticator.php#L31

The checkCode generator currently uses == to compare the user-provided code to the system generating code. It should be switched to use PHP's hash_equals function, which is able to perform the comparison in a way that does not leak timing data.

http://php.net/manual/en/function.hash-equals.php

This is important because the 30 second TOTP window is likely enough to make many attempts to validate a code. Because the project isn't under active maintenance, I would suggest adding a line to the readme referring people to a different TOTP library, such as:

https://github.com/Spomky-Labs/otphp

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.