Skip to content
/ totp Public

Simple library to generate TOTP codes and parse TOTP URIs

License

Notifications You must be signed in to change notification settings

lucasepe/totp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages