googleauthenticator

package module
v0.0.0-...-fb9b749 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2021 License: MIT Imports: 7 Imported by: 0

README

googleauthenticator

Two- / Multi- Factor Authenication (2FA / MFA) for Golang

codecov Build Status go.dev go.mod Go Report Card LICENSE

Installation

To get the package, execute:

go get github.com/dev-templates/googleauthenticator

Usage

package main

import (
    "fmt"

    "github.com/dev-templates/googleauthenticator"
)

func main {
    // generate key
    formattedKey := googleauthenticator.GenerateKey()
    authenticator := googleauthenticator.NewAuthenticator("issuer", "xxx@gmail.com", formattedKey)
    // generate uri for show
    uri := authenticator.GenerateTotpUri()
    fmt.Println(uri)
    // verify token
    passcode := "<from input>"
    if authenticator.VerifyToken(passcode) {
        // ok
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateKey

func GenerateKey() (formattedKey string)

Types

type Authenticator

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

func NewAuthenticator

func NewAuthenticator(issuer string, accountName string, formattedKey string) *Authenticator

func (*Authenticator) GenerateToken

func (a *Authenticator) GenerateToken() (passcode string)

func (*Authenticator) GenerateTotpUri

func (a *Authenticator) GenerateTotpUri() string

func (*Authenticator) VerifyToken

func (a *Authenticator) VerifyToken(passcode string) bool

Jump to

Keyboard shortcuts

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