func (c App) NewHotp(name string) revel.Result { otp, err := hotp.GenerateHOTP(numDigits, false) if err != nil { c.Flash.Error("Sorry - I couldn't generate a new HOTP!") c.FlashParams() return c.Redirect(App.Index) } qr, err := otp.QR(name) if err != nil { c.Flash.Error("Sorry - I couldn't generate a new HOTP!") c.FlashParams() return c.Redirect(App.Index) } png := base64.StdEncoding.EncodeToString(qr) code0 := otp.OTP() code1 := otp.OTP() err = c.storeHOTP(otp) if err != nil { return c.Redirect(App.Index) } c.Session["name"] = name return c.Render(name, png, code0, code1) }
func (a *Authenticator) Request(data string) (string, error) { otp, err := hotp.GenerateHOTP(a.length, false) if err != nil { return "", err } return otp.URL(data), nil }
func main() { digits := flag.Int("d", 6, "number of digits") doRand := flag.Bool("r", false, "randomise counter") flag.Parse() var label string if flag.NArg() == 1 { label = flag.Arg(0) } otp, err := hotp.GenerateHOTP(*digits, *doRand) if err != nil { fmt.Printf("! %v\n", err.Error()) return } url := otp.URL(label) png, err := otp.QR(label) if err != nil { fmt.Printf("! %v\n", err.Error()) return } filename := label if label == "" { filename = base32.StdEncoding.EncodeToString([]byte(url)) } err = ioutil.WriteFile(filename+".png", png, 0644) if err != nil { fmt.Printf("! %v\n", err.Error()) return } err = ioutil.WriteFile(filename+".txt", []byte(url), 0644) if err != nil { fmt.Printf("! %v\n", err.Error()) return } keyFile, err := hotp.Marshal(otp) if err != nil { fmt.Printf("! %v\n", err.Error()) return } err = ioutil.WriteFile(filename+".key", keyFile, 0644) if err != nil { fmt.Printf("! %v\n", err.Error()) return } }