Git Product home page Git Product logo

auth2fa's Introduction

Two-Factor Authentication (2FA) Library

This PHP library provides functionality for generating Time-based One Time Passwords (TOTP) and HMAC-based One Time Passwords (HOTP), commonly used in two-factor authentication (2FA) systems.

Features

  • TOTP Generation: Generate Time-based One Time Passwords.
  • HOTP Generation: Generate HMAC-based One Time Passwords.
  • Random Secret Key Generation: Generate random secret keys for use in TOTP and HOTP generation.

Usage

TOTP Generation

The Auth2FA::TOTP method generates a Time-based One Time Password using the provided secret key and optional time slice. totp.example.php

$totp = Auth2FA::TOTP($secret, $timeSlice);
/*
 $totp is array like: ['code'=>111222, 'expire'=>1712003400];
*/

HOTP Generation

The Auth2FA::HOTP method generates an HMAC-based One Time Password using the provided secret key and counter value. hotp.example.php

$code = Auth2FA::HOTP($secret, $counter);
/*
 $code is string like: 111222
*/

Secret Key Generation

The Auth2FA::generateSecret method generates a random secret key of the specified length.

$length = 16; // Secret key lenght
$secret = Auth2FA::generateSecret($length);
/*
 $secret is string like: OVZ7JFIPIXE4RTCE
*/

Note: There is no separate function to check the correctness of 2fa codes. You must use the generation functions to confirm the correctness of the codes sent by users.


License

This library is released under the MIT License.

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.