Coder Social home page Coder Social logo

mincdev / php-2-factor-authentication Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 0.0 10 KB

A library for securely generating a 2 factor authentication QR code to use with Google Autnenticator

License: MIT License

PHP 100.00%
2-factor-authentication 2fa 2fa-security google-authenticator google-authenticator-php php-2fa php-2factor-auth php-2-factor-authentication multi-factor qrcode

php-2-factor-authentication's Introduction

php-otpauth

A library for generating a 2 factor authentication QR code to use with Google Authenticator, Authy, etc.

Secure QRCode Creation

This library has secure QRCode creation because of the fact that the QRCode is generated locally on your server. This means that the user's secret is not passed to any third party or remote server in order to generate a code. This was inspired by the stack overflow answer by kravietz as seen here

Installation (Composer)

composer require mincdev/php-otpauth

Dependencies

This library requires the tc-lib-barcode library found at https://github.com/tecnickcom/tc-lib-barcode.

Note: The tc-lib-barcode library is maintained and owned by a separate entity.

Generating a QR Code

You can generate a QR code which can be scanned by Google Authenticator, Authy, etc. by using the below.

$otpAuth = new OtpAuthenticator();

$userName = "MrDoe";
$appName = "My Awesome App";

// Store this secret somewhere safe, as you'll need it to validate the pin later
$userSecret = $otpAuth->newSecret();

$qrBase64 = $otpAuth->getQR($userName, $appName, $userSecret);

Validating a PIN

Once your user logs in, you can validate their pin by making use of the following:

$otpAuth = new OtpAuthenticator();
$isValid = $otpAuth->validate($userSecret, $pinCode);

php-2-factor-authentication's People

Contributors

mincdev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

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.