totp

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2024 License: MIT Imports: 10 Imported by: 0

README

totp-go

TOTP (Time-based one-time password) for GO according to RFC 6238 (https://datatracker.ietf.org/doc/html/rfc6238).

Supports SHA1, SHA256 and SHA512 hashing. Generates 6,8 or 8 digits long passwords.

Example usage

package main

import (
	"fmt"
	"os"

	"github.com/ironsys-pl/totp-go"
)

func main() {
    secret := "1234567890"
    timeStepSize := 30 // 30 seconds, recommended in RFC
    hashAlgo := totp.HashAlgoSha1
    digits := 6
    // produces 6 digit password, different output every 30 seconds
    pass  := totp.Totp([]byte(secret), time.Now(), timeStepSize, hashAlgo, digits)
}

Documentation

Index

Constants

View Source
const (
	HashAlgoSha1   = "SHA1"
	HashAlgoSha256 = "SHA256"
	HashAlgoSha512 = "SHA512"
)
View Source
const TimeStepSizeDefault = 30
View Source
const TimeStepSizeMax = 31622400
View Source
const TimeStepSizeMin = 1

Variables

This section is empty.

Functions

func Totp

func Totp(secret []byte, t time.Time, timeStepSize int, hashAlgo string, digits int) string

Totp calculates time based one time password as described in RFC 6238.

Password is calculated based on secret, time, timeStepSize (in seconds, 30 is the recommended value, has to be in range of [1, 31622400]), hashing algorithm (SHA1, SHA256 and SHA512 are accepted) and digits (6, 7 or 8). Digits parameter also determines result password length.

Types

This section is empty.

Jump to

Keyboard shortcuts

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