Comments (3)
@evandrix thanks for feedback, I will dig into.
from gauth.
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.
@evandrix oh, nice! Could you please make a PR then?
from gauth.
Related Issues (2)
- base 56 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gauth.