lucasepe / totp

Simple library to generate TOTP codes and parse TOTP URIs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

totp

Simple library with no dependencies to:

Installation

go get -u github.com/lucasepe/totp

Usage

Generation

package main

import (
    "fmt"

    "github.com/lucasepe/totp"
)

func main() {
    code, err := totp.New(totp.Options{
        Secret:   "JBSWY3DPEHPK3PXP",
        Digits:   8,
        Period:   15,
        UnixTime: 32158800000,
    })
    if err != nil {
        panic(err)
    }

    fmt.Println(code)
}

URI Parsing

package main

import (
    "fmt"

    "github.com/lucasepe/totp"
)

func main() {
    opts, err := totp.ParseURI("otpauth://totp/Acme?secret=IRXW4J3UEBKGK3DMEBAW46KPNZSSC")
    if err != nil {
        panic(err)
    }

    code, err := totp.New(opts)
    if err != nil {
        panic(err)
    }

    fmt.Println(code)
}

About

Simple library to generate TOTP codes and parse TOTP URIs

License:MIT License


Languages

Language:Go 100.0%