GithubHelp home page GithubHelp logo

Comments (3)

moldabekov avatar moldabekov commented on June 14, 2024

@evandrix thanks for feedback, I will dig into.

from gauth.

evandrix avatar evandrix commented on June 14, 2024

np, i wrote this Go implementation, adapted from yours, https://github.com/pcarrier/gauth, as well as the dependency of that https://github.com/creachadair/otp

"${HOME}/.gauth" format: <Name><SPACE><Num_Digits><SPACE><Period><SPACE><Base32-secret>

main.go

package main

import (
	"log"
	"os"
	"fmt"
	"time"
	"path"
	"bytes"
	"strings"
	"strconv"
	"os/user"
	"io/ioutil"
	"encoding/csv"
	"text/tabwriter"
	"github.com/creachadair/otp"
)

func main() {
	usr,err := user.Current()
	if err != nil {log.Fatal(err)}

	cfg_fp := path.Join(usr.HomeDir,".gauth")
	cfg_data,err := ioutil.ReadFile(cfg_fp)
	if err != nil {log.Fatal(err)}

	cfg_rdr := csv.NewReader(bytes.NewReader(cfg_data))
	cfg_rdr.Comma = ' '
	cfg,err := cfg_rdr.ReadAll()
	if err != nil {log.Fatal(err)}

	tw := tabwriter.NewWriter(os.Stdout,0,2,1,' ',0)
	for _,record := range cfg {
		name,ndigit_s,period_s,secret := record[0],record[1],record[2],record[3]
		if ndigit,err:=strconv.Atoi(ndigit_s); err==nil {
			if period,err:=strconv.Atoi(period_s); err==nil {
				var cfg otp.Config
				cfg.Digits = ndigit
				cfg.TimeStep = otp.TimeWindow(period)
				cfg.ParseKey(secret)

				time := time.Now().Unix()
				period_int64,err := strconv.ParseInt(period_s,10,64)
				if err != nil {log.Fatal(err)}

				fmt.Fprintf(tw,"%s\t%s\t[%-*s]\n",name,cfg.TOTP(),period-1,strings.Repeat("=",int(time%period_int64)))
			}
		}
	}
	tw.Flush()
}

from gauth.

moldabekov avatar moldabekov commented on June 14, 2024

@evandrix oh, nice! Could you please make a PR then?

from gauth.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.