GithubHelp home page GithubHelp logo

jonfriesen / otp Goto Github PK

View Code? Open in Web Editor NEW
9.0 4.0 5.0 362 KB

A Go implementation of RFC 4226 HOTP: An HMAC-Based One-Time Password Algorithm and RFC 6238: TOTP: Time-Based One-Time Password Algorithm

License: MIT License

Go 98.50% Dockerfile 1.50%
otp hotp 2fa 2-factor rfc-4226 hmac-sha1 rfc-6238 totp password-algorithm hacktoberfest

otp's Introduction

OneTimePasswords

Build Status

This package is an implementation of RFC 4226: HOTP: An HMAC-Based One-Time Password Algorithm and RFC 6238: TOTP: Time-Based One-Time Password Algorithm with slight deviations from the RFC based on the algorithmic reference implementation and tested using the RFC test values to ensure comaptibility with other HOTP and TOTP systems.

Installation

Clone this repository into your Go src directory or pull it automatically with:

$ go get github.com/jonfriesen/otp

Usage

import "github.com/jonfriesen/otp"
...
// To generate and checking a Time base OTP
totpToken := NewTOTP("secret", Time, 8, 30, 2, sha1.New)
totp := totpToken.Generate()
isValid := totp == totpToken.Check("12345678")
...
// To generate and checking a HMAC OTP 
hotpToken := NewHOTP("secret", 0, 6, 5, sha1.New)
hotp := hotpToken.Generate()
isValid := hotp == hotpToken.Check("123456")

Considerations and Variations from RFC

Checksum

The checksum option is not included in this implementation as I feel most real world implementations don't use it or account for it.

Truncation Offset

The truncation offset is intended to give the entire hash digest the opportunity to contribute to the truncated portion of the hash. Removing this section does not make the algorithm more or less secure.

Motivation

The OTP package was created to offer a simple, close implementation of RFC 4226 and RFC 6238 for easy consumption in Go.

Contributions

Pull Requests are welcome, please include tests covering your contributions.

MIT License Copyright (c) 2022 Jonathan Friesen

otp's People

Contributors

jonfriesen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.