g2fa

package module
v0.0.0-...-757988f Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2016 License: Apache-2.0 Imports: 11 Imported by: 0

README

g2pa

Temporary password generation for two-factor authentication. Works with Google Authenticator mobile app.

Sample usage

  1. Get Google Authenticator
  2. Tap on 'Set up account'
  3. Pick 'Enter provided code'
  4. Enter account name 'GoLang console'
  5. Enter key 'PT2KHGTK7YQ3EVIK'
  6. Save
  7. Run code from below in the console. Temporary password from the console and from the app will match
package main

import (
    "fmt"
    "github.com/andrewromanenco/g2fa"
)

func main() {
    //key, err := g2fa.GenerateKey()
    //skey := g2fa.EncodeKey(key)
    skey := "PT2KHGTK7YQ3EVIK"
    key, err := g2fa.DecodeKey(skey)
    
    if err != nil {
        panic(err)
    }
    code, err := g2fa.GetTimedAuthCode(key)
    if err != nil {
        panic(err)
    }
    fmt.Println("Key: ", skey)
    fmt.Println("Temp code: ", code)
}

Documentation

Overview

Package g2fa implements temporary time based password generation for Google Authenticator app. Works accordingly to RFC 4226 and https://en.wikipedia.org/wiki/Google_Authenticator

See README for details.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeKey

func DecodeKey(skey string) ([]byte, error)

DecodeKey converts a base32 key to a binary representation.

func EncodeKey

func EncodeKey(key []byte) string

EncodeKey converts a binary key to a user friendly base32 string.

func GenerateKey

func GenerateKey() ([]byte, error)

GenerateKey generates random crypto key of requested length in bytes.

func GetTimedAuthCode

func GetTimedAuthCode(key []byte) (string, error)

GetTimedAuthCode returns a temp password valid for a 30 seconds window.

Types

This section is empty.

Jump to

Keyboard shortcuts

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