PHPackages                             krixon/multi-factor-auth - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. krixon/multi-factor-auth

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

krixon/multi-factor-auth
========================

Multi-factor authentication library for PHP7

0.5.1(6y ago)53.4k↓50%[2 PRs](https://github.com/krixon/multi-factor-auth/pulls)MITPHPPHP &gt;=7.2

Since Jul 16Pushed 3y ago3 watchersCompare

[ Source](https://github.com/krixon/multi-factor-auth)[ Packagist](https://packagist.org/packages/krixon/multi-factor-auth)[ RSS](/packages/krixon-multi-factor-auth/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (10)Used By (0)

Multi Factor Authentication
===========================

[](#multi-factor-authentication)

[![Build Status](https://camo.githubusercontent.com/d7fdbdfea02cf61ae93012962f81e7056200d03c2e8b2a3e96f42a62ad6d0fe8/68747470733a2f2f7472617669732d63692e6f72672f6b7269786f6e2f6d756c74692d666163746f722d617574682e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/krixon/multi-factor-auth)[![Coverage Status](https://camo.githubusercontent.com/7c5ef43b747fff90b0e7ad4fa2052a5d236705e23b850b50eaeb34c32d9c8850/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6b7269786f6e2f6d756c74692d666163746f722d617574682f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/krixon/multi-factor-auth?branch=master)[![Code Climate](https://camo.githubusercontent.com/ce9fb71e4e2f0b80c7c201921f0f148865b87b7c815ec170ed7192a70bb74731/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6b7269786f6e2f6d756c74692d666163746f722d617574682f6261646765732f6770612e737667)](https://codeclimate.com/github/krixon/multi-factor-auth)[![Latest Stable Version](https://camo.githubusercontent.com/5db5541f8275d635cae51adff8d2e5c02e224f5712ae5535a3b243f4f4078aa8/68747470733a2f2f706f7365722e707567782e6f72672f6b7269786f6e2f6d756c74692d666163746f722d617574682f762f737461626c65)](https://packagist.org/packages/krixon/multi-factor-auth)[![Latest Unstable Version](https://camo.githubusercontent.com/4761598b5d43f3fb11c9bd9462bec02714db2077790d2f7582022871e4494f87/68747470733a2f2f706f7365722e707567782e6f72672f6b7269786f6e2f6d756c74692d666163746f722d617574682f762f756e737461626c65)](https://packagist.org/packages/krixon/multi-factor-auth)[![License](https://camo.githubusercontent.com/b6e5da789f0adeff7ea91b70888439937d0fe8c9b5aa2725215d66680cd85126/68747470733a2f2f706f7365722e707567782e6f72672f6b7269786f6e2f6d756c74692d666163746f722d617574682f6c6963656e7365)](https://packagist.org/packages/krixon/multi-factor-auth)

[![SensioLabsInsight](https://camo.githubusercontent.com/af893536a6822aad98308b9a3fb156a2f77924669340488d0e4a167adeae6678/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f63643232643465362d343430392d343439312d396536662d3536636466376266383936342f6269672e706e67)](https://insight.sensiolabs.com/projects/cd22d4e6-4409-4491-9e6f-56cdf7bf8964)

A library for generating and verifying the codes used in multi-factor authentication systems.

Features:

- Time-based ([TOTP](https://en.wikipedia.org/wiki/Time-based_One-time_Password_Algorithm)) code generation and verification.
- Event-based ([HOTP](https://en.wikipedia.org/wiki/HMAC-based_One-time_Password_Algorithm)) code generation and verification.
- Barcode generation for easy client setup.

This library implements the following RFCs:

- [RFC4226 - HOTP: An HMAC-Based One-Time Password Algorithm](https://tools.ietf.org/html/rfc4226)
- [RFC6238 - TOTP: Time-Based One-Time Password Algorithm](https://tools.ietf.org/html/rfc6238)

It has been tested against the following multi-factor authentication tools:

- [Google Authenticator](https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2) (TOTP + HOTP)
- [Authy](https://authy.com/) (TOTP + HOTP)

Prerequisites
=============

[](#prerequisites)

- PHP 7.1+

Installation
============

[](#installation)

Install via composer
--------------------

[](#install-via-composer)

To install this library with Composer, run the following command:

```
$ composer require krixon/multi-factor-auth
```

You can see this library on [Packagist](https://packagist.org/packages/krixon/multi-factor-auth).

Install from source
-------------------

[](#install-from-source)

```
# HTTP
$ git clone https://github.com/krixon/multi-factor-auth.git
# SSH
$ git clone git@github.com:krixon/multi-factor-auth.git
```

Quick Start
===========

[](#quick-start)

Let's say you have a server side application which you want to protect using multi-factor authentication.

There are three main steps involved:

1. Generate a secret which is shared between the server and the user.
2. Configure a client application (such as Google Authenticator) with the shared secret.
3. Verify codes generated by the client application whenever the user needs to authenticate.

This library makes these steps easy.

The quickest way to get up and running is to create a new instance of the `MultiFactorAuth` class. This takes various arguments to its constructor, but there is a static factory provided which creates an instance with sensible and secure defaults. The only thing you need to provide is an "issuer" string. This is just a label which identifies the provider or service managing a user's account - i.e. your application.

```
