otp

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package otp

TOTP: https://en.wikipedia.org/wiki/One-time_password

https://datatracker.ietf.org/doc/html/rfc6238

HOTP: https://en.wikipedia.org/wiki/HMAC-based_one-time_password

https://datatracker.ietf.org/doc/html/rfc4226

Copyright 2021 Inanzzz.com

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewQR

func NewQR(uri string) ([]byte, error)

NewQR creates a new QR PNG from an OTP URI.

func NewSecret

func NewSecret() (string, error)

NewSecret creates a Base32 encoded arbitrary secret from a fixed length of 16 byte slice without having a padding sign `=` at the end.

Types

type OTP

type OTP struct {
	// contains filtered or unexported fields
}

func NewHOTP

func NewHOTP(secret string) *OTP

NewHOTP return new otp that's use HMAC-based One-Time Password. Good when sending otp via sms or email. Not recommended yet for this app since this app does not support sending any email yet.

func NewTOTP

func NewTOTP(secret string) *OTP

NewTOTP return new otp that's use Time-based One-Time Password. Good when used with mobile apps such as Microsoft Authenticator or Google Authenticator etc.

func (*OTP) CreateHOTPCode

func (o *OTP) CreateHOTPCode(counter int) (string, error)

CreateHOTPCode creates a new HOTP with a specific counter. This method is ideal if you are planning to send manually created code via email, SMS etc. The user should not be present a QR code for this option otherwise there is a high possibility that the client and server counters will be out of sync, unless the user will be forced to rescan a newly generated QR with up-to-date counter value.

func (*OTP) CreateURI

func (o *OTP) CreateURI() string

CreateURI builds the authentication URI which is used to create a QR code. If the counter is set to 0, the algorithm is assumed to be TOTP, otherwise HOTP. REF: https://github.com/google/google-authenticator/wiki/Key-Uri-Format

func (*OTP) VerifyCode

func (o *OTP) VerifyCode(code string) (bool, error)

VerifyCode talks to an algorithm specific validator to verify the integrity of the code. If the counter is set to 0, the algorithm is assumed to be TOTP, otherwise HOTP.

Jump to

Keyboard shortcuts

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