totp

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 5 Imported by: 0

README

TOTP (RFC-6238) and HOTP (RFC-4226)

codecov Go Report Card OpenSSF Scorecard

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	TimeStep time.Duration = 30 * time.Second
	TimeZero time.Time     = time.Unix(0, 0)
	Hash                   = sha512.New
	Digits                 = 10
)

Functions

func HOTP

func HOTP(counter uint64, key []byte) string

HOTP is HMAC-based One-Time Password RFC-4226

func TOTP

func TOTP(t time.Time, key []byte) string

TOTP is Time-based One-Time Password RFC-6238

Example
package main

import (
	"fmt"
	"time"

	"github.com/nikolaydubina/totp"
)

func main() {
	code := totp.TOTP(time.Date(2023, 10, 10, 11, 0, 0, 0, time.UTC), []byte("example-secret"))
	fmt.Println(code)
}
Output:

0031983894

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL