From 2ee9cae5ba123ee9da984deaf292ef0cff3f1a06 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Thu, 19 Dec 2013 00:20:00 -0700 Subject: [PATCH] Add basic Google Authenticator TOTP client. --- totpc/totpc.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 totpc/totpc.go diff --git a/totpc/totpc.go b/totpc/totpc.go new file mode 100644 index 0000000..1c86f92 --- /dev/null +++ b/totpc/totpc.go @@ -0,0 +1,43 @@ +package main + +import ( + "fmt" + "github.com/gokyle/twofactor" + "io/ioutil" + "time" +) + +func main() { + otp := twofactor.GenerateGoogleTOTP() + if otp == nil { + fmt.Println("totpc: failed to generate token") + return + } + + qr, err := otp.QR("totpc-demo") + if err != nil { + fmt.Println(err.Error()) + return + } + + err = ioutil.WriteFile("out.png", qr, 0644) + if err != nil { + fmt.Println(err.Error()) + return + } + + fmt.Println(otp.OTP()) + for { + for { + t := time.Now() + if t.Second() == 0 { + break + } else if t.Second() == 30 { + break + } + <-time.After(1 * time.Second) + } + fmt.Println(otp.OTP()) + <-time.After(30 * time.Second) + } +}